abalcerek
abalcerek

Reputation: 1819

Sending jms messages from wildfly

I'm working on jms base wildfly application (wildfly 8, java 7). I have to use event driven library based on Rx Java. I want to send jms message from on even listener which I have to provide to library function to. The problem is that standard EJB based mechanisms for sending jms messages does not work from inside Rx Java handlers. The wild guess is that I can not inject / use annotation based EJB jms mechanisms inside Rx Java stream as they are not spawned by the EJB container (or pass EJB beans as Rx Java handlers). I have tried to send jms messages from EJB singleton as from standalone java application following tutorial like this. The problem is have with this approach is that standalone instance of wildfly can not find dependency for index factory org.jboss.naming.remote.client.InitialContextFactory. Or wildfly won't even deploy if I try to add maven dependency

<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-jms-client-bom</artifactId>
    <version>${version.wildfly}</version>
    <type>pom</type>
</dependency>

to my application fat jar. Any ideas would be greatly appreciated as my understanding of EJB is quite lacking in this matter.

Upvotes: 0

Views: 128

Answers (1)

Ernesto Campohermoso
Ernesto Campohermoso

Reputation: 7391

You can use EJBs without dependency injection making a lookup to InitialContext.

After code the Singleton EJB you need to know the "EJB name on JNDI registry" after that you can do:

Context ctx = new InitialContext()
MyStatlessBeanInterface bean = ctx.lookup("FULL NAME BEAN"); 
bean.sendJMSMessage();

Wilfly prints the EJB name in the console at deployment, but you can read about conventions in:

https://docs.jboss.org/author/display/AS71/JNDI+Reference

Also you can get more information about lookup in:

https://docs.oracle.com/cd/E16439_01/doc.1013/e13981/usclient003.htm

Upvotes: 1

Related Questions