6

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?

Alex
  • 883
  • 4
  • 11
  • 23

2 Answers2

6

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.

John Ament
  • 11,595
  • 1
  • 36
  • 45
  • Thanks for your reply! But I do use `mappedName` in my injections. I think that the first two code fragments in your response are identical to the code I use. Are not they? – Alex Mar 01 '15 at 19:06
  • My topic definition is different than yours. – John Ament Mar 01 '15 at 19:34
  • I tried your code. I still have the same error for the `topic` field. The error for the `connectionFactory` field is gone. Probably something got injected there . – Alex Mar 01 '15 at 19:49
  • When you say code, you mean the descriptor change? Pl update your question to clarify. – John Ament Mar 01 '15 at 19:55
  • I updated the XML (in `standalone-full.xml`) and my Java code. I copied all three snippets from your answer and tried to deploy. If you need any more information in my question, please say what you want to see. – Alex Mar 01 '15 at 20:03
  • John, I would not like to update my question with the changes that you have suggested because I will either have to replace my own code snippets or create a question that is exceedingly long. – Alex Mar 02 '15 at 03:35
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.

Community
  • 1
  • 1
Alex
  • 883
  • 4
  • 11
  • 23