MDB不会消耗Jboss 7.1中队列中的消息

时间:2016-02-10 15:29:26

标签: jboss jms hornetq message-driven-bean

我正在使用jboss 7.1并配置发送方将消息发送到Hornet队列。我可以在Jboss管理控制台中看到,一旦发送者发送消息,消息计数就会增加,但MDB不消耗该消息。发件人和使用者都在同一个应用程序中运行(相同的java进程/ jvm)。以下是jboss Standalone-full.xml中的配置。

 <jms-connection-factories>
                    <connection-factory name="InVmConnectionFactory">
                        <connectors>
                            <connector-ref connector-name="in-vm"/>
                        </connectors>
                        <entries>
                            <entry name="java:/ConnectionFactory"/>
                        </entries>
                    </connection-factory>
                    <connection-factory name="RemoteConnectionFactory">
                        <connectors>
                            <connector-ref connector-name="netty"/>
                        </connectors>
                        <entries>
                            <entry name="RemoteConnectionFactory"/>
                            <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                        </entries>
                    </connection-factory>
                    <pooled-connection-factory name="hornetq-ra">
                        <transaction mode="xa"/>
                        <connectors>
                            <connector-ref connector-name="in-vm"/>
                        </connectors>
                        <entries>
                            <entry name="java:/JmsXA"/>
                        </entries>
                    </pooled-connection-factory>
                </jms-connection-factories>

                <jms-destinations>
                    <jms-queue name="testQueue">
                        <entry name="queue/MyQueue"/>
                        <entry name="java:jboss/exported/jms/queue/test"/>
                    </jms-queue>
                </jms-destinations>

邮件发件人:

Context context = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)context.lookup("queue/MyQueue");
QueueSender sender = session.createSender(queue);

//1. Sending TextMessage to the Queue 
TextMessage message = session.createTextMessage();
message.setText("Hello EJB3 MDB Queue!!!");
sender.send(message);

MDB:

@MessageDriven(name="MessageDistributor", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/MyQueue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class MessageReceiver implements MessageListener  {  
 public void onMessage(Message message) {
        System.out.println("Message received from Queue...");
    }
}

jboss日志中没有错误或异常。我可以看到消息进入队列但不被MDB消耗。在此先感谢。

1 个答案:

答案 0 :(得分:0)

您的发件人应该发送到“/ jms / queue / test”而不是“queue / MyQueue”。外部只显示“/ jms / queue / test”。 假设它在一个单独的JVM中运行。