Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to create an <strong>InitialContext</strong> that uses the <strong>JNDI</strong> server in Geronimo. You can then use this to lookup your JMS Connection Factory and Queue.</p> <p>The following example was adapted from <a href="http://forums.sun.com/thread.jspa?threadID=5283256" rel="nofollow noreferrer">http://forums.sun.com/thread.jspa?threadID=5283256</a> to use the Geronimo JNDI Factory.</p> <pre><code>Context jndiContext = null; ConnectionFactory connectionFactory = null; Connection connection = null; Session session = null; Queue queue = null; MessageProducer messageProducer = null; try { //[1] Create a JNDI API InitialContext object. Hashtable properties = new Hashtable(2); // CHANGE these to match Geronimos JNDI service properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); properties.put(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201"); jndiContext = new InitialContext(properties); //[2] Look up connection factory and queue. connectionFactory = (ConnectionFactory)jndiContext.lookup("jms/ConnectionFactory"); queue = (Queue)jndiContext.lookup("jms/Queue"); //[3] // - Create connection // - Create session from connection; false means session is not transacted. // - Create sender and text message. // - Send messages, varying text slightly. connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(queue); //send a message TextMessage message = session.createTextMessage(this.jTextSend.getText()); messageProducer.send(message); //example for send some object //ObjectMessage message = session.createObjectMessage(); //MyObj myObj = new MyObj ("Name"); //this class must be serializable //message.setObject(myObj ); //messageProducer.send(message); } catch(Exception ex) { LOG.error(ex); } finally { if(connection !=null) { try { connection.close(); } catch(JMSException e) { LOG.error(e); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload