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
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.
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.
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.
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With