Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring/injecting a JMS connection factory and a topic in WildFly

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?

like image 636
Alex Avatar asked Mar 01 '15 17:03

Alex


People also ask

How do I consume messages from another WildFly JMS server?

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.

What is the default JMS connection factory in WildFly?

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.

How do I create a JMS 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.

How to connect and consume messages from remote JMS server?

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 .


1 Answers

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.

like image 100
John Ament Avatar answered Oct 16 '22 00:10

John Ament