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

10,091

Solution 1

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.

Solution 2

As explained here, standalone.xml supports Java EE Web-Profile plus some extensions, standalone-full.xml supports Java EE Full-Profile.

My problem was that I defined the JMS connection factory and the JMS topic in standalone-full.xml. jBoss WildFly uses standalone.xml by default.

The answers to this question explain how to configure WildFly to use standalone-full.xml instead of standalone.xml. Switching to standalone-full.xml solved my problem.

Share:
10,091
Alex
Author by

Alex

Updated on June 16, 2022

Comments

  • Alex
    Alex almost 2 years

    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?