2012-12-27 85 views
1

我正在開發一個使用JBoss 6.1作爲後端的web應用程序。
我使用「目標」屬性創建了一個消息驅動bean:「queue/searchtabQueue」和「目標類型」屬性「javax.jms.Queue」。JBoss消息驅動bean,onMessage不叫

由於https://community.jboss.org/wiki/HowToCreateJMSQueuetopicInAS6下描述我設法創建我的隊列 「隊列/ searchtabQueue」( 「searchtab-將hornetq-jms.xml文件」):

<configuration xmlns="urn:hornetq" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"> 
    <queue name="searchtabQueue"> 
    <entry name="/queue/searchtabQueue"/> 
    </queue> 
</configuration> 

部署後,在管理控制檯中,我看到了我在狀態爲「up」的「JMS隊列」下排隊。

在無狀態Bean我做一下了隊列,其工作原理是正確的,也 發送拋出也不例外:

Context ctx = new InitialContext(p); // Create the initial context 
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); 
Queue queue = (Queue) ctx.lookup("queue/searchtabQueue"); 
Connection connect = factory.createConnection(); 
javax.jms.Session session = connect.createSession(false, 0); 
MessageProducer sender = session.createProducer(queue); 
TextMessage msg = session.createTextMessage(); 
msg.setText("abc"); 
sender.send(msg); 
connect.close(); 

但該消息驅動Bean的onMessage方法不調用。

我錯過了什麼?

非常感謝提前

沃爾夫岡

更新:我MDB-代碼:

我的消息驅動bean具有下面的代碼:

@MessageDriven(activationConfig = { 
     @ActivationConfigProperty(propertyName = "destinationType", 
            propertyValue = "javax.jms.Queue"), 
     @ActivationConfigProperty(propertyName = "destination", 
            propertyValue = "queue/searchtabQueue"), 
     @ActivationConfigProperty(propertyName = "acknowledgeMode", 
            propertyValue = "Auto-acknowledge") 
    }) 
public class SearchTableBean implements MessageListener { 

    public void onMessage (Message message) { 
    } 
} 
+0

你可以爲你的MDB添加代碼嗎?這是一個遠程隊列嗎? – CoolBeans

+0

Hello CoolBeans,我爲我的MDB添加了代碼 –

回答

1

現在是工作,我改變了看法的東西。

查找代碼:

Context ctx = new InitialContext(p); // Create the initial context 
Queue queue = (Queue) ctx.lookup("java:jboss/exported/jms/queue/searchtab"); 
QueueConnectionFactory factory = (QueueConnectionFactory) 
    ctx.lookup("ConnectionFactory"); 
QueueConnection connect = factory.createQueueConnection(); 
javax.jms.QueueSession session = connect.createQueueSession(false, 
    QueueSession.AUTO_ACKNOWLEDGE); 
TextMessage msg = session.createTextMessage("Hello World"); 
QueueSender sender = session.createSender(queue); 
sender.send(msg); 
connect.close(); 

隊列創建XML文件:

<configuration xmlns="urn:hornetq" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"> 
    <queue name="searchtabQueue"> 
     <entry name="queue/searchtab"/> 
     <entry name="java:jboss/exported/jms/queue/searchtab"/> 
    </queue> 
</configuration>  

MDB代碼:

@MessageDriven(activationConfig = { 
     @ActivationConfigProperty(propertyName = "destinationType", 
            propertyValue = "javax.jms.Queue"), 
     @ActivationConfigProperty(propertyName = "destination", 
            propertyValue = "queue/searchtab"),  
     @ActivationConfigProperty(propertyName = "acknowledgeMode", 
            propertyValue = "Auto-acknowledge") 
    }) 
public class SearchTableBean implements MessageListener { 
    public void onMessage (Message message) { 
    System.out.println("abc"); 
} 
0

根據該規範,則必須調用

connect.start(); 

來激活消息傳遞過程。