Trouble with JMS and message-driven beans on WildFly 8.2.0 Final and 9.0.0 CR2
alashchuk Jul 23, 2015 5:32 PMHi all -
I am looking for some help troubleshooting a JMS queue send/receive issue on WildFly 8.2.0. My issue is similar to what is described in this thread: https://developer.jboss.org/thread/235447, however the posted solution does not work for me. In a nutshell, the message queue and connection factory are created and can be injected into the application on deployment. The message is written to the queue by the sender without any errors. However, the MDB listener never receives the message. Furthermore, when the application is deployed and after the message is posted to the queue, the runtime statistics for the queue are shown as having 15 subscribers, but no messages posted and no messages waiting in the queue.
After experimenting with the code for a couple of days, I was able to boil it down to a simple (and fairly boilerplate) example. The code is posted below.
The sender:
@Stateless @LocalBean public class MQTester { @Resource(mappedName = "jms/ReplyQueueConnectionFactory") private ConnectionFactory replyQueueConnectionFactory; @Resource(mappedName = "jms/ReplyQueue") private Queue replyQueue; @TransactionAttribute(TransactionAttributeType.REQUIRED) public void testMQ() { try { Connection jmsConn = replyQueueConnectionFactory.createConnection(); if (jmsConn != null) { try { jmsConn.start(); Session jmsSession = jmsConn.createSession(true, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = jmsSession.createProducer(replyQueue); TextMessage message = jmsSession.createTextMessage(); message.setText("Message Text"); messageProducer.send(message); } finally { jmsConn.close(); } } } catch(JMSException ex) { System.err.println("Error sending message: " + ex); } } }
The listener:
@MessageDriven(mappedName = "jms/ReplyQueue", activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") }) @TransactionManagement(value=TransactionManagementType.CONTAINER) @TransactionAttribute(TransactionAttributeType.REQUIRED) public class MQReceiver implements MessageListener { @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void onMessage(Message message) { TextMessage txtMsg = (TextMessage) message; try { System.out.println(txtMsg.getText()); } catch (Exception ex) { System.err.println("Error receiving message: " + ex); } } }
Properties defined in jboss-ejb3.xml:
<?xml version="1.0" encoding="UTF-8"?> <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:security:1.1" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1" impl-version="2.0"> <enterprise-beans> <session> <ejb-name>MQTester</ejb-name> <resource-ref> <res-ref-name>jms/ReplyQueue</res-ref-name> <jndi-name>java:/jms/ReplyQueue</jndi-name> </resource-ref> <resource-ref> <res-ref-name>jms/ReplyQueueConnectionFactory</res-ref-name> <jndi-name>java:/jms/ReplyQueueConnectionFactory</jndi-name> </resource-ref> </session> <message-driven> <ejb-name>MQReceiver</ejb-name> <activation-config> <activation-config-property> <activation-config-property-name>destination</activation-config-property-name> <activation-config-property-value>java:/jms/ReplyQueue</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> </enterprise-beans> </jboss:ejb-jar>
Both the sender and the MDB are deployed in the same EJB jar inside of an EAR archive, and there is also a web application in the same EAR, which calls the testMQ method of the sender on button click.
The connection factory uses the in-vm connector.
I've tried playing around with JNDI names of the queues and with transaction options to no avail. I was able to turn on trace logging in HornetQ and, according to the logs, the message is sent to the queue successfully. I can post the relevant log entries if it helps.
Can anyone provide any insight into what may be going on? Is it a problem that both the sender and the listener are part of the same deployment unit? Are there any transactional options that I am not supplying properly? I should probably mention that I've had similar code working on GlassFish for several years now, so at least superficially it should be functional. I've checked both WildFly 8.2.0 and 9.0.0 CR2, and both exhibit the same behavior.
Thanks in advance for your help,
Alex