关于Websphere MQ,我有两个关于messageId的一般性问题。
1)该字段可以实现队列中的同步通信吗?例如,在以下源代码中:
MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Hello World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
system_default_local_queue.put(hello_world,pmo);
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = hello_world.messageId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
system_default_local_queue.get(retrievedMessage, gmo);检索到的消息将是hello_world消息的确切响应,并且将只检索此消息,而将队列中的所有其他消息留在队列中,即使有超过此时间的消息也是如此?
2)如果是这样的话,可以用两个队列来完成吗?示例:客户端:
MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Hello World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
input_queue.put(hello_world,pmo);
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = hello_world.messageId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
output_queue.get(retrievedMessage, gmo);服务器端:
while(true){
MQMessage inMessage= new MQMessage();
input_queue.get(mqMessage ,gmo);
//actions to get the contents of the inMessage and create proper response
MQMessage outMessage= new MQMessage();
//write the proper response to outMessage
outMessage.messageId = inMessage.messageId;
output_queue.put(outMessage, pmo);
}发布于 2012-01-17 08:06:56
我认为你使用“同步”的方式是错误的。您在上面#1中描述的是真的- MsgID的GET将只检索这一条消息。但是,这不是同步消息传递示例。
您所描述的客户机/服务器交换的一般情况是正确的。如果许多应用程序实例总是通过ID查找消息,那么它们可以使用相同的回复队列,这是一种常见的模式。通常发生的情况是,MsgID被复制到相关ID,因此,人们不会在retrievedMessage对象上初始化msgID,而是希望看到correlID被初始化。当然,行为完全取决于服务器应用程序的行为,有些确实会将请求msgID复制到应答msgID。
只需确保GET by msgID或correlID包含等待,以便晚到的消息有地方可去。同样,在这种模式下,如果在某个时间范围内(例如一两个小时)没有收到回复,则回复将过期。
https://stackoverflow.com/questions/8887300
复制相似问题