哪位达人能告诉我MQmessage 的messageId跟correlationId到底有什么不同,该怎么用?

leopard353 2009-03-02 10:52:25
哪位达人能告诉我MQmessage 的messageId跟correlationId到底有什么不同,该怎么用?
...全文
1146 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
enshiwzw 2009-06-10
  • 打赏
  • 举报
回复
MessageId
public byte[] MessageId {get; set;}
For an MQQueue.Get() call, this field specifies the message identifier of the message to be retrieved. Normally, the queue manager returns the first message with a message identifier and correlation identifier that match those specified. The special value MQC.MQMI_NONE allows any message identifier to match.

For an MQQueue.Put() call, this specifies the message identifier to use. If MQC.MQMI_NONE is specified, the queue manager generates a unique message identifier when the message is put. The value of this member variable is updated after the put, to indicate the message identifier that was used.

The default value is MQC.MQMI_NONE.

你没有置值的情况下是没有的.
enshiwzw 2009-03-02
  • 打赏
  • 举报
回复
新产生了一个消息A, A被处理,...然后得到B(可能是COPY等各种处理),那么A有一个messageID,B也有一个messageID,但correlationId如果不指定,一般为A的messageID.
leopard353 2009-03-02
  • 打赏
  • 举报
回复
/* 设置MQEnvironment 属性以便客户机连接 */
MQEnvironment.hostname = MQ_HOSTNAME;
MQEnvironment.channel = MQ_CHANNEL;
MQEnvironment.CCSID = 1381;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES_CLIENT);

/* 连接到队列管理器 */
MQQueueManager qMgr = new MQQueueManager(MQ_MANAGER);

/* 设置打开选项以便打开用于输出的队列,如果队列管理器停止,我们也已设置了选项去应对不成功情况 */
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;

/* 打开打开队列 */
MQQueue queue = qMgr.accessQueue(requestQueue, openOptions, null,
null, null);

/* 设置放置消息选项,我们将使用默认设置 */
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = pmo.options + MQC.MQPMO_NEW_MSG_ID;
pmo.options = pmo.options + MQC.MQPMO_SYNCPOINT;

/* 创建消息缓冲区 */
MQMessage outMsg = new MQMessage();

/* 设置MQMD 格式字段 */
outMsg.format = MQC.MQFMT_STRING;
outMsg.messageFlags = MQC.MQMT_REQUEST;
outMsg.replyToQueueName = replyToQueue;
outMsg.replyToQueueManagerName = MQ_MANAGER;

/* 准备用户数据消息 */
String msgString = msg;
outMsg.writeString(msgString);
// outMsg.messageId=InetAddress.getLocalHost().getHostAddress().getBytes();
/* 在队列上放置消息 */
queue.put(outMsg, pmo);

/* 提交事务 */
qMgr.commit();
logPrint("c:\\sender.log",
" The send message is : " + msgString
+ ", messageId is : "+new String(outMsg.messageId)+", correlationId is : "
+new String(outMsg.correlationId)+"\n");
// System.out.println(" The message has been Successfully put\n");

/* 关闭请求队列 */
queue.close();

/* 设置打开选项以便队列响应 */
openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue respQueue = qMgr.accessQueue(replyToQueue, openOptions,
null, null, null);
MQMessage respMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();

/* 在同步点控制下获取消息 */
gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;
gmo.options = gmo.options + MQC.MQGMO_WAIT;
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
respMessage.correlationId = outMsg.messageId;

/* 获取响应消息 */
respQueue.get(respMessage, gmo);
String response = respMessage.readString(respMessage
.getMessageLength());
logPrint("c:\\receiver.log", " The receive message is : " + response
+ ", messageId is : "+new String(respMessage.messageId)
+", correlationId is : "+new String(respMessage.correlationId)+"\n");

// System.out.println("The response message is : " + response + "\n");
qMgr.commit();
respQueue.close();
qMgr.disconnect();

为什么这样println(respMessage.correlationId)跟pringln(outMsg.messageId)明明不同,但我的接收段却能自动匹配发送端发出的信息

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧