2012-01-16 211 views
1

我已經關於messageId在WebSphere MQ兩個一般性問題:的WebSphere MQ消息

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); 
} 
+0

Mq_queue被指定爲默認異步,在一側是生產者 - >信道 - >消費者,如果創建了兩個分離的通道put_channel和get_channel,但message_flow仍保持不變第二例子是舒適用於數據流 - - >異步 – mKorbel 2012-01-16 22:53:16

回答

2

我想您正在使用 「同步」 走錯了路。你在上面#1中描述的是真的 - MsgID的GET將只檢索那一條消息。但是,這不是一個同步消息傳遞示例。

你介紹的客戶機/服務器交換的一般情況下是正確的。這是一種常見模式,如果許多應用程序實例總是通過ID查找消息,則它們可以使用相同的答覆隊列。通常情況下會發生什麼情況是,msgid是複製到相關ID,但這樣不是retrievedMessage對象初始化msgID的,一個希望看到correlID代替初始化。當然,該行爲是完全依賴於服務器應用程序的行爲,而有些則要求msgID複製到答覆msgID

只要確保通過msgIDcorrelID的GET包括等待,這樣一個遲到的消息有地方可去。同樣,在這種模式下,如果答覆在某個時間範圍內沒有收到 - 例如一兩個小時,答覆就會過期。