Java JMS客户端路由
大家好,我正在工作中开发一个JMS客户机。我了解我的JMS资源,即ConnectionFactory、QueueConnectionFactory和Queue/Topic。我已经使用java开发了它,它在本地服务器上使用glassfish运行良好 我想确定我从这个路由点收到的Connectionfactory或QueueConnectionFactory是什么。我将如何实现连接到vPN服务器。CSD端口为7016,CSD IP:10.10.10.76Java JMS客户端路由,java,jms,Java,Jms,大家好,我正在工作中开发一个JMS客户机。我了解我的JMS资源,即ConnectionFactory、QueueConnectionFactory和Queue/Topic。我已经使用java开发了它,它在本地服务器上使用glassfish运行良好 我想确定我从这个路由点收到的Connectionfactory或QueueConnectionFactory是什么。我将如何实现连接到vPN服务器。CSD端口为7016,CSD IP:10.10.10.76 <routingPoint>
<routingPoint>
<name>CSD</name>
<inboundQueue>interfaceCsdOut</inboundQueue>
<outboundQueue>interfaceCsdIn</outboundQueue>
<context>glassfish-csd</context>
<matchingKey>DESTINATION</matchingKey>
<controlPoint>SWITCH</controlPoint>
</routingPoint>
听起来您想从外部客户端连接到这些队列 在这种情况下,这个客户机需要一些客户机JAR,比如JMS客户机。您的提供商URL是: iiop://10.10.10.76:7016 (检查端口以确保它是引导端口) Connectionfactory或QueueConnectionFactory不可用 TestQueueConnectionFactory 和您的队列: jms/托管 如果您使用的是websphere,并且具有重要的jms客户机JAR,那么您的客户机代码可能如下所示:(对于Glassfish,应该类似)
我们假设使用CSD interfaceCsdOut interfaceCsdIn glassfish CSD目的地交换机我的队列是interfaceCsdIn
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "mq://127.0.0.1:7676");
// Create the initial context for remote JMS server
InitialContext cntxt = new InitialContext(props);
//System.out.println("Context Created");
// JNDI Lookup for QueueConnectionFactory in remote JMS Provider
QueueConnectionFactory qFactory = (QueueConnectionFactory)cntxt.lookup("TestQueueConnectionFactory");
// Create a Connection from QueueConnectionFactory
Connection connection = qFactory.createConnection();
//System.out.println("Connection established with JMS Provider ");
// Initialise the communication session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the message
TextMessage message = session.createTextMessage();
message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
message.setText(finalm);
// JNDI Lookup for the Queue in remote JMS Provider
Queue queue = (Queue)cntxt.lookup("jms/Escrow");
// Create the MessageProducer for this communication
// Session on the Queue we have
MessageProducer mp = session.createProducer(queue);
// Send the message to Queue
mp.send(message);
//System.out.println(finalm);
// Make sure all the resources are released
mp.close();
session.close();
cntxt.close();
import java.io.File;
import java.io.StringWriter;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class SimpleClientLast {
public static void main(String args[]) throws JMSException, NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://10.10.10.76:7016");
Context jndiContext = null;
try {
jndiContext = new InitialContext(env);
} catch (NamingException e) {
System.out.println("Could not create JNDI API context: "
+ e.toString());
System.exit(1);
}
ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext
.lookup("TestQueueConnectionFactory");
Connection qConn = connectionFactory.createConnection();
Session qSession = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q = (Queue) jndiContext.lookup("jms/Escrow");
System.out.println("before");
MessageProducer producer = qSession.createProducer(q);
TextMessage message = qSession.createTextMessage();
System.out.println("JSON begin: ");
String jsonText = "{"mytext":"myTextDetails"}"
System.out.println(jsonText);
message.setText(jsonText);
producer.send(message);
System.out.println("JSON end.");
System.out.println("after");
producer.close();
qSession.close();
qConn.close();
}