1

我正在开发一个使用 JBoss 6.1 作为后端的网络应用程序。
我用“destination”属性创建了一个消息驱动bean:“queue/searchtabQueue”和“destination type”属性“javax.jms.Queue”。

https://community.jboss.org/wiki/HowToCreateJMSQueuetopicInAS6中所述,我设法创建了我的队列“queue/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>

部署后,在管理控制台中,我在“JMS 队列”下看到状态为“up”的队列。

在无状态 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) {
  }
}
4

2 回答 2

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>      

数据库代码:

@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");
 }  
于 2013-01-09T15:04:08.327 回答
0

根据规格,您必须致电

connect.start(); 

激活消息传递过程。

于 2014-04-23T19:57:04.470 回答