JMS semi-newbie - "simplified" interface with ejb-jar.xml
stdunbar Apr 10, 2015 5:36 PMHello,
I converted a JMS 1 application to JMS 2 recently. This is under Wildfly 8.2.0. I've got a JMS topic that I want to publish and subscribe to and I'm a bit stuck. I want to use ejb-jar.xml for some of the configuration as I want to have a virtual host environment with many almost duplicate WAR files. I originally started down the annotation route but got stuck because I had "global" JMS topics. So now I want to externalize the configuration.
I have a JMS topic named, in JNDI, "java:/jms/myTopic". I created this globally via jboss-cli.sh with "jms-topic add --topic-address=myTopic --entries=java:/jms/myTopic". My MDB looks like:
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = "doesntmatter"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") }) public class MyListener implements MessageListener { @Override public void onMessage(Message message) { } }
My ejb-jar.xml (in WEB-INF) looks like:
<message-driven> <ejb-name>MyListener</ejb-name> <ejb-class>a.b.c.MyListener</ejb-class> <activation-config> <activation-config-property> <activation-config-property-name>destination</activation-config-property-name> <activation-config-property-value>/jms/myTopic</activation-config-property-value> </activation-config-property> </activation-config> </message-driven>
On the MDB side, this works fine.
Now, I'd like to "fix" the publisher side.
My code looks like:
@Stateless public class MessageProducer { @Resource(name = "jms/myTopic") private Topic topic; @Inject private JMSContext context; public void sendMessage(String msg) { ObjectMessage message = context.createObjectMessage(); message.setObject(msg); context.createProducer().send(topic, message); }
And I've tried like heck to figure out what to put into ejb-jar.xml. I currently have:
<session> <ejb-name>ProjectMessageProducer</ejb-name> <ejb-class>a.b.c.MessageProducer</ejb-class> <message-destination-ref> <message-destination-ref-name>jms/myTopic</message-destination-ref-name> <message-destination-type>javax.jms.Topic</message-destination-type> <injection-target> <injection-target-class>a.b.c.MessageProducer</injection-target-class> <injection-target-name>topic</injection-target-name> </injection-target> </message-destination-ref> </session>
I know that it tries to inject it because I get:
15:31:01,217 WARN [org.jboss.as.ee] (MSC service thread 1-3) JBAS011001: Could not resolve message-destination-ref java:comp/env/jms/myTopic
But trying to rename this and create the destination as specified cannot be done. On startup Wildfly tells me
Caused by: java.lang.RuntimeException: JBAS011846: Illegal context in name: java:comp/env/jms/myTopic
plus I wouldn't know how to change the MDB side.
So if this makes any sense, can someone give me some pointers? I'm more than happy to change my code or architecture on this. I just need some pointers.