客户端用于远程JMS队列 [英] client for remote JMS queue
问题描述
我在远程glassfish服务器上配置了JMS队列。我试图从我的本地机器连接这个队列。是否有可能直接连接到这台服务器,或者我需要通过一些经纪人/代理连接?它是如何工作的? (我在jms区域新鲜)
非常感谢
如果您的客户端应用程序在Glassfish外部运行,一个开放mq客户端的简单代码示例。
为了使它工作,您需要引用glassfishInstall / mq / lib目录中的2个openmq jar - imq.jar和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);
队列myQueue =新队列(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);
}
}
}
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
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);
}
}
}
这篇关于客户端用于远程JMS队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!