Reputation: 2184
I have a JMS implementation (producer and consumer) in my server Glashfish 4. The consumer code works when I executed as appclient in glashfish.
Producer.java
@Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/MyQueue")
private static Queue queue;
...
JMSContext context = connectionFactory.createContext();
context.createProducer().send((Destination) queue, message);
Consumer.java
@Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/MyQueue")
private static Queue queue;
...
JMSConsumer consumer;
JMSContext context = connectionFactory.createContext();
consumer = context.createConsumer((Destination) queue);
Message m = consumer.receive(1000);
I need make a consumer remote standalone java app.
In my glassfish server, I edited properties of JMS Connection Factory and I added property addressList with value x.x.x.x:xxxx
Any ideas?
Upvotes: 0
Views: 708
Reputation: 47
First in your lib folder of your standalone java app copy file gf-client.jar. The location of this file is your_glassfish_installation_directory/glassfish/lib.
Code
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);
QueueConnectionFactory cf = (QueueConnectionFactory)ic.lookup("jms/MyConnectionFactory");
Queue queue =(Queue)ic.lookup("jms/queue");
Upvotes: 0