当前位置:网站首页>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文档。问题的可能原因包括以下几个方面:
- 安全问题
- 队列定义不正确
- 队列管理器未启动
边栏推荐
- 1、 Introduction to C language
- Scala basic tutorial -- 13 -- advanced function
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
- How is the entered query SQL statement executed?
- MySQL常用增删改查操作(CRUD)
- Li Kou brush question diary /day7/6.30
- [go ~ 0 to 1] read, write and create files on the sixth day
- 爬虫初级学习
- Redis master-slave replication
猜你喜欢

Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)

Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组

力扣刷题日记/day7/6.30
![[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation](/img/63/8d5f875b4409511628faf2914836d3.png)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation

谷粒商城(一)

Deleting nodes in binary search tree

Li Kou brush question diary /day6/6.28

Scala基础教程--15--递归

Neglected problem: test environment configuration management

uni-app与uviewUI实现仿小米商城app(附源码)
随机推荐
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
力扣刷题日记/day1/2022.6.23
Reptile elementary learning
李迟2022年6月工作生活总结
一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)
Li Kou brush question diary /day5/2022.6.27
uni-app与uviewUI实现仿小米商城app(附源码)
Neglected problem: test environment configuration management
[HCIA continuous update] network management and operation and maintenance
TCP两次挥手,你见过吗?那四次握手呢?
Blue bridge: sympodial plant
2022年字节跳动日常实习面经(抖音)
SIGMOD’22 HiEngine论文解读
Is it safe to download the mobile version of Anxin securities and open an account online
Scala基础教程--18--集合(二)
Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
Scala基础教程--17--集合
Li Kou brush question diary /day3/2022.6.25
Lua emmylua annotation details
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation