I'm trying to create a temporary JMS queue using JMS 2.0 in Wildfly 10, and an injected connection factory.
I am injecting my ConnectionFactory using @JMSConnectionFactory. This works fine.
@Inject @JMSConnectionFactory("java:/jms/RemoteConnectionFactory") JMSContext jmsContext
Creating a temporary queue also works fine:
Destination jmsQueue = jmsContext.createTemporaryQueue();
Creating a publisher and publishing messages works okay as well:
JMSProducer producer = jmsContext.createProducer();
TextMessage msg = jmsContext.createTextMessage(Long.toString(new Date().getTime()));
producer.send(jmsQueue, msg);
However, how do I create a listener for the queue? I cannot use an MDB as the temp queue is not predefined. If I try to create a consumer, and assign a message listener to it, I get the following error message:
JMSConsumer consumer = jmsContext.createConsumer(jmsQueue);
consumer.setMessageListener(new MessageListener() {
...
...
});
Error trace:
Caused by: javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
at org.apache.activemq.artemis.ra.ActiveMQRASession.checkStrict(ActiveMQRASession.java:1452)
at org.apache.activemq.artemis.ra.ActiveMQRAMessageConsumer.setMessageListener(ActiveMQRAMessageConsumer.java:123)
at org.apache.activemq.artemis.jms.client.ActiveMQJMSConsumer.setMessageListener(ActiveMQJMSConsumer.java:59)
So it appears that I cannot explicity set a message listener with a JEE controlled connection factory. But given that it is a temp queue, I cannot create an MDB since the Destination is not known at compile time. So how do I listen to a temp queue?