wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Properties in InitialContext for SimpleQueueReceiver.java, MQ5.3 server remotely Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Properties in InitialContext for SimpleQueueReceiver.java, MQ5.3 server remotely" Watch "Properties in InitialContext for SimpleQueueReceiver.java, MQ5.3 server remotely" New topic
Author

Properties in InitialContext for SimpleQueueReceiver.java, MQ5.3 server remotely

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
What are the properties to be set in Initial Context for using SimpleQueueReceiver.java from Sun's JMS tutorial?

I am using MQ5.3 and the server machine is remote from my local computer. I am using it as Proof of Concept for simplest form of P2P messaging.

My QueueName is: QueueName
QueManagerName: QMDOCDAA

MQ Server is set as:
SET MQSERVER=QMDOCDAA.SVRCONN/TCP/BNDOC-AP01D(1414)

Channel is: SVRCONN
Server Name: BNDOC-AP01D
Port: 1414

Which API of InitialContext should I use?

bind(Name, Object)
bind(String, Object)
addToEnvironment(String, Object)

Please give me an example, using thge paramets above so that I can run SimpleQueueReceiver.java


I am copying SimpleQueueReceiver.java from Sun's tutorial below:

import javax.jms.*;
import javax.naming.*;

public class SimpleQueueReceiver {

/**
* Main method.
*
* @param args the queue used by the example
*/
public static void main(String[] args) {
String queueName = "myQueue";
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;

/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext();
//TODO: NEED TO POPULATE context

} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}

/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}

/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create receiver, then start message delivery.
* Receive all text messages from queue until
* a non-text message is received indicating end of
* message stream.
* Close connection.
*/
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
message.getText());
} else {
break;
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
}
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
I am using WSAD5.1.1 as IDE for Proof of concept. Application will be deployed in WAS as proof of concept.
 
jQuery in Action, 2nd edition
 
subject: Properties in InitialContext for SimpleQueueReceiver.java, MQ5.3 server remotely