当前位置:网站首页>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文档。问题的可能原因包括以下几个方面:
- 安全问题
- 队列定义不正确
- 队列管理器未启动
边栏推荐
- 【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
- [210] usage of PHP delimiter
- C语言打印练习
- vbs或vbe如何修改图标
- Torchdrug tutorial
- Why are some online concerts always weird?
- File processing examples of fopen, FREAD, fwrite, fseek
- [HCIA continuous update] WAN technology
- Li Kou brush question diary /day3/2022.6.25
- The block:usdd has strong growth momentum
猜你喜欢

力扣刷题日记/day8/7.1

The controversial line of energy replenishment: will fast charging lead to reunification?

How to improve development quality
![[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

Li Kou brush question diary /day8/7.1

2022 national CMMI certification subsidy policy | Changxu consulting

Imitation of numpy 2

力扣刷题日记/day2/2022.6.24

vbs或vbe如何修改图标

Scala基础教程--19--Actor
随机推荐
Scala基础教程--12--读写数据
Li Kou brush question diary /day6/6.28
【机器学习的数学基础】(一)线性代数(Linear Algebra)(上+)
删除二叉搜索树中的节点附图详解
ITSS运维能力成熟度分级详解|一文搞清ITSS证书
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Mxnet implementation of googlenet (parallel connection network)
Interpretation of SIGMOD '22 hiengine paper
输入的查询SQL语句,是如何执行的?
Lua EmmyLua 注解详解
SIGMOD’22 HiEngine论文解读
Mysql5.7 installation tutorial graphic explanation
Li Kou brush question diary /day7/2022.6.29
线上MySQL的自增id用尽怎么办?
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Pb extended DLL development (super chapter) (VII)
android使用SQLiteOpenHelper闪退
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
Scala basic tutorial -- 15 -- recursion
力扣刷题日记/day3/2022.6.25