当前位置:网站首页>IBM WebSphere MQ retrieving messages
IBM WebSphere MQ retrieving messages
2022-07-04 19:00:00 【User 7741497】
IBM WebSphere MQ Retrieve messages
Retrieve messages
To retrieve messages , Do the following :
- according to “ Create connection objects ” Create a connection object as described in . under these circumstances , Please create
%Net.MQRecv
Example .Connection
Object has a message queue , You can retrieve messages from . - Call the following methods as needed :
%Get()
- Return a string message by reference as the first parameter .%GetStream()
- Given the initialized file character stream , This method retrieves messages from the queue , And put it into the file associated with the stream . Please note that , The... Of the stream must be setFilename
Property to initialize it . Binary streams are not supported .
- Check the value returned by the called method . see also “ Get the error code ”. please remember , When the queue is empty ,IBM
WebSphere MQ
return2033
. - After retrieving the message , call
Connection
Object's%Close()
Method to release the handle of the dynamic link library .
Example 1:ReceiveString()
The following class methods are from mqtest
Queue retrieval messages .
///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
}
Example 2:ReceiveCharacterStream()
The following methods can retrieve longer messages , Because it uses %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
}
Update message information
%Net.MQSend
and %Net.MQRecv
Class also provides the following methods :
%CorId()
( By quoting ) Update the association of the last read message ID.
%ReplyQMgrName()
( By quoting ) Update the reply queue manager name of the last read message .
%ReplyQName()
( By quoting ) Update the reply queue name of the last read message .
Troubleshooting
If you are using IBM WebSphere MQ
Of InterSystems IRIS Interface encountered a problem , You should first determine whether the client is installed correctly and can communicate with the server . To perform such a test , have access to IBM WebSphere MQ
Sample program provided . The executable is located at IBM WebSphere MQ
Client's bin Directory .
The following steps describe how to Windows
Use these sample programs on . On other operating systems , The details may vary ; Please refer to IBM Document and check the name of the file that exists in your client .
- Create a file called
MQSERVER
Environment variables of . The format of its value should bechannel_name/Transport/server
, amongchannel_name
Is the name of the channel to be used ,Transport
Is a string indicating the transfer to be used , andserver
Is the name of the server . for example :S_Antigua/TCP/Antigua
- On the command line , Enter the following command :
amqsputc queue_name queue_manager_name
among ,QUEUE_NAME
Is the name of the queue to be used ,QUEUE_MANAGER_NAME
Is the name of the queue manager . for example :
amqsputc mqtest QM_antigua
If amqsputc
The command does not recognize , Please make sure it is updated PATH
Environment variables to include IBM WebSphere MQ
Client's bin Catalog .
- You should see a few lines of code , As shown below :
Sample AMQSPUT0 start
target queue is mqtest
- Now you can send messages . Just type in each message , Then press... After each message Enter Press the key . for example :
sample message 1
sample message 2
- After sending the email , Press two times. Enter key . then , You will see the line shown below :
Sample AMQSPUT0 end
- To complete this test , We will retrieve the messages sent to the queue . Type the following command on the command line :
amqsgetc queue_name queue_manager_name
among ,QUEUE_NAME
Is the name of the queue to be used ,QUEUE_MANAGER_NAME
Is the name of the queue manager . for example :
- then , You should see a starting line , Followed by the message sent before , As shown below :
Sample AMQSGET0 start
message <sample message 1>
message <sample message 2>
- This sample program briefly waits to receive any other messages , Then display the following :
no more messages
Sample AMQSGET0 end
If the test fails , Please refer to IBM file . The possible causes of the problem include the following aspects :
- safety problem
- The queue definition is incorrect
- The queue manager did not start
边栏推荐
猜你喜欢
随机推荐
激进技术派 vs 项目保守派的微服务架构之争
Reptile elementary learning
Rookie post station management system based on C language
怎么开户才是安全的,
Scala basic tutorial -- 15 -- recursion
线上MySQL的自增id用尽怎么办?
物联网应用技术的就业前景和现状
fopen、fread、fwrite、fseek 的文件处理示例
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
Li Kou brush question diary /day5/2022.6.27
力扣刷题日记/day7/6.30
Microservice architecture debate between radical technologists vs Project conservatives
TorchDrug教程
How to improve development quality
Imitation of numpy 2
Li Kou brush question diary /day7/2022.6.29
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
6.26cf simulation match B: solution to array reduction problem
6.26CF模拟赛B:数组缩减题解