当前位置:网站首页>IBM WebSphere MQ检索邮件
IBM WebSphere MQ检索邮件
2022-07-04 17:10:00 【用户7741497】
IBM WebSphere MQ检索邮件
检索邮件
要检索邮件,请执行以下操作:
- 按照“创建连接对象”中的说明创建连接对象。在这种情况下,请创建
%Net.MQRecv
的实例。Connection
对象有一个消息队列,可以从中检索消息。 - 根据需要调用以下方法:
%Get()
-通过引用返回字符串消息作为第一个参数。%GetStream()
-给定初始化的文件字符流,此方法从队列中检索消息,并将其放入与该流关联的文件中。请注意,必须设置流的Filename
属性才能对其进行初始化。不支持二进制流。
- 检查调用的方法返回的值。请参阅“获取错误代码”。请记住,当队列为空时,IBM
WebSphere MQ
返回2033
。 - 检索完消息后,调用
Connection
对象的%Close()
方法以释放动态链接库的句柄。
示例1:ReceiveString()
下面的类方法从mqtest
队列检索消息。
///Method returns string or null or error message
ClassMethod ReceiveString() As %String
{
Set recv=##class(%Net.MQRecv).%New()
Set queue="mqtest"
Set qm="QM_antigua"
Set chan="S_antigua/TCP/antigua(1414)"
Set logfile="c:\mq-recv-log.txt"
Set check=recv.%Init(queue,qm,chan,logfile)
If 'check Quit recv.%GetLastError()
Set check=recv.%Get(.msg)
If 'check {
Set reasoncode=recv.%GetLastError()
If reasoncode=2033 Quit ""
Quit "ERROR: "_reasoncode
}
Quit msg
}
示例2:ReceiveCharacterStream()
以下方法可以检索更长的消息,因为它使用%GetStream()
:
/// Method returns reason code from IBM WebSphere MQ
ClassMethod ReceiveCharacterStream() As %Integer
{
Set recv=##class(%Net.MQRecv).%New()
Set queue="mqtest"
Set qm="QM_antigua"
Set chan="S_antigua/TCP/antigua(1414)"
Set logfile="c:\mq-recv-log.txt"
Set check=recv.%Init(queue,qm,chan,logfile)
If 'check Quit recv.%GetLastError()
//initialize the stream and tell it what file to use
//make sure filename is unique we can tell what we received
Set longmsg=##class(%FileCharacterStream).%New()
Set longmsg.Filename="c:\mq-received"_$h_".txt"
Set check=recv.%GetStream(longmsg)
If 'check Quit recv.%GetLastError()
Quit check
}
更新消息信息
%Net.MQSend
和%Net.MQRecv
类还提供以下方法:
%CorId()
(通过引用)更新上次读取的邮件的关联ID。
%ReplyQMgrName()
(通过引用)更新上次读取的消息的回复队列管理器名称。
%ReplyQName()
(通过引用)更新上次读取的消息的回复队列名称。
Troubleshooting
如果在使用IBM WebSphere MQ
的InterSystems IRIS接口时遇到问题,应该首先确定客户端是否安装正确并且可以与服务器通信。要执行这样的测试,可以使用IBM WebSphere MQ
提供的示例程序。可执行文件位于IBM WebSphere MQ
客户端的bin目录中。
以下步骤介绍如何在Windows
上使用这些示例程序。在其他操作系统上,细节可能会有所不同;请参考IBM文档并检查您的客户端中存在的文件的名称。
- 创建一个名为
MQSERVER
的环境变量。它的值的格式应该是channel_name/Transport/server
,其中channel_name
是要使用的通道的名称,Transport
是指示要使用的传输的字符串,而server
是服务器的名称。例如:S_Antigua/TCP/Antigua
- 在命令行中,输入以下命令:
amqsputc queue_name queue_manager_name
其中,QUEUE_NAME
是要使用的队列的名称,QUEUE_MANAGER_NAME
是队列管理器的名称。例如:
amqsputc mqtest QM_antigua
如果amqsputc
命令无法识别,请确保已更新PATH
环境变量以包括IBM WebSphere MQ
客户端的bin目录。
- 应该会看到几行代码,如下所示:
Sample AMQSPUT0 start
target queue is mqtest
- 现在可以发送消息了。只需键入每条消息,然后在每条消息后按Enter键即可。例如:
sample message 1
sample message 2
- 发送完邮件后,按两次Enter键。然后,将看到如下所示的行:
Sample AMQSPUT0 end
- 要完成此测试,我们将检索发送到队列的消息。在命令行中键入以下命令:
amqsgetc queue_name queue_manager_name
其中,QUEUE_NAME
是要使用的队列的名称,QUEUE_MANAGER_NAME
是队列管理器的名称。例如:
- 然后,应该看到一个起始行,后跟之前发送的消息,如下所示:
Sample AMQSGET0 start
message <sample message 1>
message <sample message 2>
- 此示例程序短暂等待接收任何其他消息,然后显示以下内容:
no more messages
Sample AMQSGET0 end
如果测试失败,请参考IBM文档。问题的可能原因包括以下几个方面:
- 安全问题
- 队列定义不正确
- 队列管理器未启动
边栏推荐
- Summary of subsidy policies across the country for dcmm certification in 2022
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- Thawte通配符SSL证书提供的类型有哪些
- 学习路之PHP--phpstudy创建项目时“hosts文件不存在或被阻止打开”
- Scala basic tutorial -- 19 -- actor
- An example of multi module collaboration based on NCF
- 输入的查询SQL语句,是如何执行的?
- General environmental instructions for the project
- android使用SQLiteOpenHelper闪退
- 基于unity的愤怒的小鸟设计
猜你喜欢
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Weima, which is going to be listed, still can't give Baidu confidence
I wrote a learning and practice tutorial for beginners!
基于lex和yacc的词法分析器+语法分析器
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
How to modify icons in VBS or VBE
Scala basic tutorial -- 18 -- set (2)
力扣刷题日记/day2/2022.6.24
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Machine learning concept drift detection method (Apria)
随机推荐
能源行业的数字化“新”运维
Interpretation of SIGMOD '22 hiengine paper
Scala基础教程--12--读写数据
Wireshark packet capturing TLS protocol bar displays version inconsistency
删除二叉搜索树中的节点附图详解
Mysql5.7 installation tutorial graphic explanation
Stars open stores, return, return, return
Scala basic tutorial -- 15 -- recursion
General environmental instructions for the project
Microservice architecture debate between radical technologists vs Project conservatives
SIGMOD’22 HiEngine论文解读
Halcon模板匹配
Principle and application of ThreadLocal
An example of multi module collaboration based on NCF
基于unity的愤怒的小鸟设计
力扣刷题日记/day5/2022.6.27
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
力扣刷题日记/day1/2022.6.23
[system disk back to U disk] record the operation of system disk back to U disk