Tenho uma classe EJB que escreve uma mensagem em uma fila JMS e gostaria de consumir esta mensagem a partir de um MessageDrivenBean (MDB) instalado em outro servidor.
A minha classe escreve na fila JMS com sucesso, porém o servidor não consome a mensagem. Nenhum erro é apresentado, a mensagem fica na fila sem ser consumida.
O usuário guest foi criado. Os testes estão sendo realizados em duas instâncias do JBoss na minha máquina local rodando em portas diferentes.
Quando o MDB está no mesmo EAR do EJB cliente (local), funciona.
Meu ambiente é JBoss EAP 7.1 com Java 8.
Classe EJB que escreve na fila:
@Stateless
public class ManagerService {
public void writeQueue() throws NamingException {
InitialContext context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)context.lookup("java:/jms/birt_connectionFactory");
Queue queue = (Queue)context.lookup("java:/jms/birt_queue");
try(JMSContext jmsContext = factory.createContext("guest", "guest")) {
JMSProducer producerPDF = jmsContext.createProducer();
String message = "Hello distant world!";
producerPDF.send(queue, message);
System.out.println("PDF sender: " + message);
}
}
}
Classe MDB que recebe a mensagem:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:/jms/birt_queue"),
@ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:/jms/birt_connectionFactory"),
@ActivationConfigProperty(propertyName = "user", propertyValue = "guest"),
@ActivationConfigProperty(propertyName = "password", propertyValue = "guest"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "7"),
@ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=127.0.0.1;port=8180")
})
public class PDFQueueReceiver implements MessageListener {
@Override
public void onMessage(Message message) {
TextMessage textMessage = (TextMessage)message;
try {
System.out.println("Remote PDF receiver: " + textMessage.getText());
}
catch (JMSException e) {
e.printStackTrace();
}
}
}
standalone.xml do servidor JBoss cliente
<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
<server name="default">
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="birt_queue" entries="java:/jms/birt_queue" durable="false"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<connection-factory name="birt_connectionFactory" entries="java:/jms/birt_connectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
</subsystem>