0
消耗來自隊列消息,我使用的JBoss 7.1和配置發送方發送該消息到大黃蜂隊列。我可以在Jboss管理控制檯中看到,一旦發送者發送消息但MDB沒有使用消息,消息數就會增加。發件人和使用者都在同一個應用程序中運行(同一個java進程/ jvm)。以下是jboss Standalone-full.xml中的配置。MDB未在JBoss中7.1
<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佔用。提前致謝。
有什麼地方纏着我大約有發件人是AUTO_ACKNOWLEDGE,沒有做過HornetQ的,但我似乎記得有與在ActiveMQ的問題......還看到你正在使用XA,是有可能,該消息已被寫入但事務未完成,因此無法將消息傳遞給MDB?否則的話看起來很合適 –
@ScottSosna ..感謝您的回覆。我嘗試刪除AUTO_ACKNOWLEDGE,但仍然沒有選擇MDB。我使用了相同的配置,並創建了2個獨立的應用程序在Jboss上運行,並且一切正常。 – code1234
我實際上是在考慮發件人,而不是消費者,但我不確定。 –