Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31292

JNDI lookup for producer

From thufir <hawat.thufir@gmail.com>
Newsgroups comp.lang.java.programmer
Subject JNDI lookup for producer
Date 2015-03-09 01:05 +0000
Organization A noiseless patient Spider
Message-ID <mdirkd$7ms$1@thufir.eternal-september.org> (permalink)

Show all headers | View raw


How is JNDI used to perform a lookup?  the connection parameters in 
jndiContext are loaded from jndi.properties, and that's fine.

How do I pass those parameters to jmsProducer or jmsContext?

The producer and consumer are on different JVM's on different machines, 
same network. 


sample code:

package net.ensode.glassfishbook;

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 jndiContext = new InitialContext();
        System.out.println(jndiContext.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();
    }
}


the sample is from:

Java EE 7 with GlassFish 4 Application Server
By: David R. Heffelfinger

http://isbn.directory/book/978-1-78217-688-6




While the above code works when the consumer is on the same JVM and same 
machine, how is the remote lookup achieved?


thanks,

Thufir

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

JNDI lookup for producer thufir <hawat.thufir@gmail.com> - 2015-03-09 01:05 +0000

csiph-web