jQuery in Action, 3rd edition
The moose likes EJB and other Java EE Technologies and the fly likes Using JMS on a client only, outside of a container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Using JMS on a client only, outside of a container" Watch "Using JMS on a client only, outside of a container" New topic

Using JMS on a client only, outside of a container

Gerben Feenstra

Joined: Feb 21, 2011
Posts: 14

I have a standalone desktop application 'A' which needs to send messages to remote application 'B' running inside a JEE container. Application B has a JMS-queue to recieve messages. Application A should have minimal changes, and for Application B I have no access to functionality or source code whatsoever.

So the plan is to make a jar-library which can be used by creating a single call with some parameters to it from within Application A. The library should put messages on the queue in Application B.

I followed the Java EE 5 tutorial from oracle, in particular the part about JMS that has a 'server' (earthmdb demo) and a client (jupiterclient demo) running separately (http://docs.oracle.com/javaee/5/tutorial/doc/bnchx.html). I use the 'server' to mimic Application B so I can test my code. It is a simple class implementing the MessageListener interface and an onMessage() method. This is working just fine; I see messages get send from the client-application and they're being received in the onMessage() method correctly.

However, they both run inside the same Glassfish container. So I tried to seperate the client to a standalone application to eventually be able to put it in a jar that is to be used by application A.
I used Apache ActiveMQ as a JEE implementation, so I don't need to run inside a JEE/glassfish-container. The messages are send to "TapServiceQueue" running in the glassfish-container on the same machine (for now) on port 17294. My code runs, messages get send, but they are not received on the server-side somehow :/

Here's is the code of my client class:

I created my app as a Maven-app inside netbeans, so dependencies are taken care of automatically.
In my client I do a createQueue:

This seems rather strange to me, since the queue already exists. I've been searching for ages for a solution now, but there does not seem to be a way to get an existing queue reference :s How to do this? Can you guys see something wrong in my code? Or is my approach not the correct one somehow?

Any suggestions?

OS: Ubuntu 11.04
JAVA: 1.7
JEE: 5
IDE: Netbeans 7.2
JEE-container: Glassfish 3+

For completeness, here is the server-side code

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

The way I do it is to get a QueueConnectionFactory from the server via JNDI. From there I can create a QueueConnection. And then I get a Queue from the server, also via JNDI.

I'm connecting to a standalone JMS server, not a Java EE container, but the principle should be the same, you should be able to connect to your server via JNDI. But I can't tell you exactly how.
Gerben Feenstra

Joined: Feb 21, 2011
Posts: 14
I found this example:

Then I should be able to get the connectionFactory from the context with this:

and the queue:

But I don't know what values to use in the properties to connect to my glassfish container. What type of InitialContextFactory should I use? What protocol should I use? vm:// or tcp://, or something else?

I tried using com.sun.enterprise.naming.SerialInitContextFactory and the url: iiop://
But then I get an Exception:

This is driving me crazy. How hard can it be to remotely connect to a queue and put a message on it?
Gerben Feenstra

Joined: Feb 21, 2011
Posts: 14
This is solved, created new thread for the latest problem: http://www.coderanch.com/t/594744/EJB-JEE/java/Cannot-remotely-find-JNDI-resources#2711264
I agree. Here's the link: http://aspose.com/file-tools
subject: Using JMS on a client only, outside of a container
It's not a secret anymore!