I'd like to do some experiments with JMS on jBoss WildFly 8.2.
The default WildFly standalone-full.xml
configuration file has the following fragments:
<hornetq-server>
<connectors>
...
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>
...
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
...
</jms-connection-factories>
<jms-destinations>
<!-- this destination I have added myself as I need a "topic", but
the default configuration has only two preconfigured "queues". -->
<jms-topic name="MyTestTopic">
<entry name="java:/jms/topic/MyTestTopic"/>
</jms-topic>
</jms-destinations>
</hornetq-server>
I am trying to inject this connection factory and this topic into an EJB in the following way:
@Stateless
public class JmsPublisher {
@Resource(mappedName = "java:/ConnectionFactory")
ConnectionFactory jmsConnectionFactory;
@Resource(mappedName = "java:/jms/topic/MyTestTopic")
Topic topic;
But I get the following error message at deployment:
Operation ("deploy") failed ... Services with missing/unavailable dependencies" => ...
...JmsPublisher\".jmsConnectionFactory is missing [jboss.naming.context.java.ConnectionFactory]"
...JmsPublisher\".topic is missing [jboss.naming.context.java.jms.topic.MyTestTopic]"
What am I doing wrong?
Another option for consuming messages from another WildFly JMS Server is to include the Connection properties directly in your MDB. This approach can be particularly useful if you are unable to modify the application server configuration and create a JMS Bridge or a Pooled Connection Factory to a remote JMS Server.
Since JMS 2.0, a default JMS connection factory is accessible to EE application under the JNDI name java:comp/DefaultJMSConnectionFactory. WildFly messaging subsystem defines a pooled-connection-factory that is used to provide this default connection factory.
In the Connect UI navigate to Instance Admin -> Event Handling -> JMS Click the "Commands" drop down menu and select "New Connection Factory" Save your changes. Click the + icon in the right most column. This will create a destination queue for this Connection Factory.
In order to connect and consume messages from a remote JMS Server you have mainly three options: Use a JMS Bridge: This approach is discussed in this tutorial: Configuring JMS Bridge with WildFly .
You should inject your destinations/connection factories using mappedName
, and you may want to consider the JMS 2.0 new APIs - JMSContext
@Resource(mappedName = "java:/topic/someTopic")
private Topic topic;
Assuming you have an entry like this
<jms-topic name="someTopic">
<entry name="topic/someTopic"/>
</jms-topic>
For connection factories, it's recommended to use the default injection point
@Resource
private ConnectionFactory connectionFactory;
but even better, just use @Inject JMSContext context
and send messages using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With