Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

client for remote JMS queue

I have a JMS queue configured on remote glassfish server. I'm trying to connect this queue from my local machine. Is it possible to connect directly to this server or I need to connect via some broker/agent? How does it work? (I'm fresh in jms area) Many thanks

like image 548
speedingdeer Avatar asked Jun 24 '13 13:06

speedingdeer


People also ask

What is a JMS client?

The term “JMS client” refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two styles of messaging: the point−to−point and publis−and−subscribe messaging styles.

Can a JMS queue have multiple consumers?

Support for multiple-consumer queues is a Message Queue feature (the JMS specification defines messaging behavior in the case of only one consumer accessing a queue). When multiple consumers access a queue, the load-balancing among them takes into account each consumer's capacity and message processing rate.

How do I connect to a JMS server?

You can connect to any JMS server by using the Java Naming and Directory Interface (JNDI) to locate an existing JMS connection factory. Depending on where the connection factory is bound, the connection URL can begin with the string lookup or the string jndi.


1 Answers

If your client application is running outside Glassfish here is a simple code example for an open mq client.

To get it to work you will need to reference 2 openmq jars from the glassfishInstall/mq/lib directory - imq.jar and jms.jar

import com.sun.messaging.ConnectionConfiguration;
import com.sun.messaging.ConnectionFactory;
import com.sun.messaging.Queue;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

public class TestJmsClientStandalone2 {

    public static void main( String[] args ) throws JMSException
    {
        ConnectionFactory connFactory = new ConnectionFactory();
        connFactory.setProperty(ConnectionConfiguration.imqAddressList, "remotehostip:7676");

        Queue myQueue = new Queue("myRemoteQueue");

        try (Connection connection = connFactory.createConnection(); 
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
                MessageProducer producer = session.createProducer(myQueue)) {

            Message message = session.createTextMessage("this is my test message");
            producer.send(message);
        }
    }
}
like image 111
Stewart Evans Avatar answered Oct 02 '22 18:10

Stewart Evans