当前位置:网站首页>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文档。问题的可能原因包括以下几个方面:
- 安全问题
- 队列定义不正确
- 队列管理器未启动
边栏推荐
- Machine learning concept drift detection method (Apria)
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- Lua emmylua annotation details
- General environmental instructions for the project
- The block:usdd has strong growth momentum
- 6.26cf simulation match B: solution to array reduction problem
- Reptile elementary learning
- 1、 Introduction to C language
- Scala basic tutorial -- 14 -- implicit conversion
- 【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
猜你喜欢
Scala基础教程--13--函数进阶
力扣刷题日记/day8/7.1
Mxnet implementation of googlenet (parallel connection network)
What types of Thawte wildcard SSL certificates provide
uni-app与uviewUI实现仿小米商城app(附源码)
Machine learning concept drift detection method (Apria)
Imitation of numpy 2
力扣刷题日记/day4/6.26
Deleting nodes in binary search tree
蓝桥:合根植物
随机推荐
能源行业的数字化“新”运维
Halcon模板匹配
Pb extended DLL development (super chapter) (VII)
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
激进技术派 vs 项目保守派的微服务架构之争
Principle and application of ThreadLocal
未来几年中,软件测试的几大趋势是什么?
Scala basic tutorial -- 12 -- Reading and writing data
蓝桥:合根植物
Wireshark packet capturing TLS protocol bar displays version inconsistency
Why are some online concerts always weird?
中国农科院基因组所汪鸿儒课题组诚邀加入
Reptile elementary learning
ThreadLocal原理与使用
C language printing exercise
[system disk back to U disk] record the operation of system disk back to U disk
谷粒商城(一)
Is it safe to download the mobile version of Anxin securities and open an account online
My colleagues quietly told me that flying Book notification can still play like this
Grain Mall (I)