2009-09-25 28 views
0

我嘗試使用bean管理事務在weblogic 10.0.1中的EJB2(legacy sucks ;-)無狀態會話bean中接收JMS消息。從JMS隊列文件夾定義看起來像Weblogic10中的JMS隊列能夠發送但不能接收的EJB2會話Bean

<uniform-distributed-queue name="ReqQueue"> 
    <default-targeting-enabled>true</default-targeting-enabled> 
    <delivery-params-overrides> 
    <delivery-mode>Non-Persistent</delivery-mode> 
    </delivery-params-overrides> 
    <quota>QuotaCrc</quota> 
    <jndi-name>xxx.ReqQueue</jndi-name> 
    <load-balancing-policy>Round-Robin</load-balancing-policy> 
</uniform-distributed-queue> 
<uniform-distributed-queue name="RespQueue"> 
    <default-targeting-enabled>true</default-targeting-enabled> 
    <delivery-params-overrides> 
    <delivery-mode>Non-Persistent</delivery-mode> 
    </delivery-params-overrides> 
    <quota>QuotaCrc</quota> 
    <jndi-name>xxx.RespQueue</jndi-name> 
    <load-balancing-policy>Round-Robin</load-balancing-policy> 
</uniform-distributed-queue> 

在bean的業務方法不啓動事務,所以JMS操作不是事務性的。所執行代碼是

InitialContext ictx = new InitialContext(); 
QueueConnectionFactory cf = (QueueConnectionFactory) 
         ictx.lookup("weblogic.jms.ConnectionFactory"); 
Queue responseQueue = (Queue) ictx.lookup("RespQueue"); 
conn = cf.createConnection(); 
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
MessageConsumer receiver = session.createConsumer(responseQueue); 
ObjectMessage response = (ObjectMessage) receiver.receive(30000); 

的問題是,receiver.receive立即返回空而沒有任何阻擋,而不管隊列的內容。根據JMS API文檔,帶有超時的receiver.receive在超時後返回null,如果目標關閉,則立即返回null。如果我使用bean管理的事務,容器管理的事務或根本沒有事務,問題是一樣的。將JMS消息發佈到另一個隊列。無論我是否使用同一方法發送,Receive都會立即返回null。

爲什麼隊列關閉,或爲什麼看起來如此?

不幸的是MDB是不是一種選擇,因爲我們必須通過隧道JMS同步調用(我不想愚弄的泥;-)

+0

我不明白爲什麼MDB不是一個選項。 – 2009-10-07 03:46:43

+0

,因爲我們想要擺脫EJB – 2009-10-07 08:11:01

+0

在J2EE容器中使用JMS消息的標準方式是使用MDB,它被稱爲最簡單的EJB 2.x.所以我仍然不明白爲什麼你更喜歡使用**更復雜的無狀態會話Bean(SLSB)。我會擺脫SLSB,但MDB是好的國際海事組織。 – 2009-10-07 19:04:18

回答

0

的球,周圍太多之前 的MessageConsumer接收器= session.createConsumer(responseQueue); put conn.start();

+0

不幸的是我無法驗證這一點,因爲整個故事的做法不同,問題沒有出現。當檢查API文檔時,它說:「一個JMS客戶端通常創建一個連接,一個或多個會話,以及一些消息生產者和消費者。當連接創建時,它處於停止模式。這意味着沒有消息正在傳遞。「所以我想說你是對的,那就是解決方案。 – 2009-12-17 09:34:02

0

創建連接後,需要啓動它才能進入接收器模式。 試試這個

...... 
conn = cf.createConnection(); 
conn.start(); 
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
...... 
相關問題