在IBM MQ客户端中传递ID [英] Passing ids in IBM MQ client
问题描述
我将消息从一个队列读到另一个队列.但是我的相关ID不会保留.
I read the messages from one queue to another queue. However my correlation ids are not preserved.
如果导入队列中的消息的相关性ID为"ABC12345",则当我将其放入导出队列时,相关性ID的值将不同.
If the correlation id is "ABC12345" for a message in the import queue, when i put it into the export queue, the value of the correlation id is different.
我如何在两个队列之间始终保持相同的相关ID 有唯一的消息ID?
How do i keep the same correlation id between the 2 queues and always have a unique message id?
获取:
mqQueue.Get(mqMsg);
string messageID = Convert.ToString(mqMsg.MessageId);
string correlationID = Convert.ToString(mqMsg.CorrelationId);
例如,如果相关性ID为"000123456789",则在读取后将其放回原位,则同一条消息的值将被更改.
If for example if the correlation id is "000123456789", then after read, while putting it back , the value gets changed for the same message.
输入:
mqMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(correlationID);
mqQueue.Put(mqMsg, mqPutMsgOpts);
我正在通过MQ.NET类使用MQ PUT和GET选项.
I am using MQ PUT and GET options via MQ.NET classes.
推荐答案
当我将消息放入另一个队列时,下面的代码片段保留了相关ID.在我的示例中,我执行以下操作:
The code snippet below preserves the correlation id when I put message to another queue. In my sample I do the following:
1)将消息发送到具有唯一相关性ID的importQ
.
2)从importQ
获取该消息.
3)将收到的消息放入exportQ
1) Put a message to importQ
with unique correlation ID.
2) Get that message from importQ
.
3) Put the received message to exportQ
public static void preserveCorreLid()
{
Hashtable mqProps = new Hashtable();
MQQueueManager qm = null;
String strCorrelId = "00123456789";
try
{
mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
mqProps.Add(MQC.CHANNEL_PROPERTY, "NET.CLIENT.CHL");
mqProps.Add(MQC.HOST_NAME_PROPERTY, "localhost");
mqProps.Add(MQC.PORT_PROPERTY, 2099);
qm = new MQQueueManager("QM", mqProps);
MQQueue importQ = qm.AccessQueue("IMPORTQ", MQC.MQOO_INPUT_SHARED |MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING );
MQMessage mqPutMsg = new MQMessage();
mqPutMsg.WriteString("This is an import message");
mqPutMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(strCorrelId);
MQPutMessageOptions mqpmo = new MQPutMessageOptions();
importQ.Put(mqPutMsg,mqpmo);
MQMessage respMsg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.WaitInterval = 3000;
gmo.Options = MQC.MQGMO_WAIT;
try
{
importQ.Get(respMsg, gmo);
}
catch (MQException ex)
{
Console.Write(ex);
Console.WriteLine("Queue Name : " + importQ.Name + ":");
}
importQ.Close();
MQQueue exportQ = qm.AccessQueue("EXPORTQ", MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING);
exportQ.Put(respMsg);
exportQ.Close();
qm.Disconnect();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
这篇关于在IBM MQ客户端中传递ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!