对于JMS Point-to-Point producer,根据Java EE 7 with GlassFish 4 Application Server的第203页,如何执行远程查找?我想为这个生产者指定一个IP地址192.168.1.3:
输出,其中 CORBA查找的JNDI属性已登录到控制台:
thufir@doge:~$
thufir@doge:~$ appclient -client NetBeansProjects/JMSPTPProducer/dist/JMSPTPProducer.jar
Mar 08, 2015 4:58:18 AM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.0.0.Final
Mar 08, 2015 4:58:18 AM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter: Version: 5.1 (Build 9-b) Compile: July 29 2014 1229
Mar 08, 2015 4:58:18 AM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter starting: broker is REMOTE, connection mode is TCP
Mar 08, 2015 4:58:18 AM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter Started:REMOTE
{org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}
Sending the following message: Testing, 1, 2, 3. Can you hear me?
Sending the following message: Do you copy?
Sending the following message: Good bye!
thufir@doge:~$
我可以使用从jndi.properties
加载的CORBA JNDI参数,也许可以将这些值传递给?
代码:
package net.ensode.glassfishbook;
import static java.lang.StrictMath.log;
import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class MessageSender {
@Resource(mappedName = "jms/CrmConnectionFactory")
// @Resource(mappedName = "jms/GlassFishBookConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/CrmQueue")
// @Resource(mappedName = "jms/GlassFishBookQueue")
private static Queue queue;
public void produceMessages() throws NamingException {
Context ctx = new InitialContext();
System.out.println(ctx.getEnvironment().toString());
JMSContext jmsContext = connectionFactory.createContext();
JMSProducer jmsProducer = jmsContext.createProducer();
String msg1 = "Testing, 1, 2, 3. Can you hear me?";
String msg2 = "Do you copy?";
String msg3 = "Good bye!";
System.out.println("Sending the following message: "
+ msg1);
jmsProducer.send(queue, msg1);
System.out.println("Sending the following message: "
+ msg2);
jmsProducer.send(queue, msg2);
System.out.println("Sending the following message: "
+ msg3);
jmsProducer.send(queue, msg3);
}
public static void main(String[] args) throws NamingException {
new MessageSender().produceMessages();
}
}
我一直在浏览这本教科书并使用Google搜索,但请原谅,我不知道如何实现远程JMS查找。
虽然我非常喜欢这种蓬松/ frodo example,但我不确定如何指定IP地址。
另见:
http://docs.oracle.com/cd/E19182-01/820-7853/ghyco/index.html