[問題] JMS的Queue

看板java作者 (毛毛)時間15年前 (2010/08/30 23:28), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
各位前輩好 小弟目前正在撰寫訊息傳遞的程式 撰寫的程式有三支 以下用P1 P2 P3稱之 基本上P1跟P3的程式碼幾乎相同 ------- -------- P1 Q P2 Q1 P3 ------- -------- 以上是示意圖 P1跟P2之間使用一個queue P2跟P3之間使用一個queue 傳遞的資料型態是TextMessage P2中有宣告兩個queue P1跟P2一起執行或者P2跟P3一起執行的話 執行的結果正確 但是如果三支程式一起執行的話 例如P1傳送訊息給P2,P2回傳給P1,如果P3這時候選擇從P2接收訊息 變成說P3接收到原本P2要回傳給P1的訊息 (程式中的傳送接收有使用SWITCH來手動做控制) 檢查發現,似乎是Q Q1沒有發揮作用 所有的資料都是丟到同一個Queue 參考的書上也並未提及兩個queue的介紹 以下是小弟P2中宣告queue的程式碼 煩請各位前輩指點 不好意思 補上JMS提供者是使用 swiftMQ 2.1.3版 MQUtility mq = null; MQUtility mq1 = null; QueueConnectionFactory queueConnectionFactory = null; QueueConnectionFactory queueConnectionFactory1 = null; Queue queue = null; Queue queue1 = null; try { mq = new MQUtility(".", "mq.config"); mq1 = new MQUtility(".", "mq.config"); // connection factory lookup queueConnectionFactory = (QueueConnectionFactory)mq.getConnectionFactory(); queueConnectionFactory1 = (QueueConnectionFactory)mq1.getConnectionFactory(); // queue lookup queue = (Queue)mq.getDestination(); queue1 = (Queue)mq1.getDestination(); } catch(Exception e) { System.out.println("Administered objects lookup failed: " + e.toString()); System.exit(1); } QueueConnection queueConnection = null; QueueConnection queueConnection1 = null; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { TextMessage textMessage = null; TextMessage textMessage1 = null; // create a queue connection using default identity queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection1 = queueConnectionFactory1.createQueueConnection(); // create a queue session QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSession queueSession1 = queueConnection1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // create receiver for the specified queue QueueReceiver queueReceiver = queueSession.createReceiver(queue); QueueReceiver queueReceiver1 = queueSession1.createReceiver(queue1); QueueSender queueSender = queueSession.createSender(queue); QueueSender queueSender1 = queueSession1.createSender(queue1); // start message delivery queueConnection.start(); queueConnection1.start(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.9.65.80

08/30 23:31, , 1F
整面都是queue 眼都花了....XD
08/30 23:31, 1F
※ 編輯: chisilence 來自: 124.9.65.80 (08/30 23:41)

08/31 00:57, , 2F
好可怕的naming
08/31 00:57, 2F
文章代碼(AID): #1CUyuvHI (java)