ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » Clustering » Connecting to Cluster Queue using JNDI

Post new topic  Reply to topic
 Connecting to Cluster Queue using JNDI « View previous topic :: View next topic » 
Author Message
Bathe
PostPosted: Tue Mar 02, 2010 9:33 am    Post subject: Connecting to Cluster Queue using JNDI Reply with quote

Newbie

Joined: 02 Mar 2010
Posts: 1

Hi,

I am using following standard JMSClient program to connect to Clustered queue. But I am getting following exception:
javax.naming.NameNotFoundException: Object NPG.ESB.OSS.RQI.01 not found on queue manager QMMNGS1


JMS Client Code:
--------------------

Code:
import javax.naming.*;
import java.util.*;
import java.io.*;
import javax.jms.*;
import javax.jms.Queue;

public class JMSClient {

Properties jndiProperties = null;
Context ctx = null;
Queue queue = null;
QueueConnectionFactory qcf = null;

public static void main(String[] args) {
JMSClient pm = new JMSClient(args);
try {
pm.connectToJNDI();
pm.doLookups();
pm.sendMessage("Hello World!");
} catch (Exception nex) {
System.err.println("Runtime Exception:" + nex);
System.exit(1);
}
pm.closeCtx();
System.exit(1);

}

public void doLookups() throws javax.naming.NamingException {
qcf = lookupQueueConnectionFactory();
System.out.println("Queue Connection Factory Retrieved:");
queue = lookupQueue();
System.out.println("Queue Retrieved");
}

public void sendMessage(String messageText) throws javax.jms.JMSException {
QueueConnection qc = qcf.createQueueConnection();
ConnectionMetaData cmd = qc.getMetaData();
Enumeration enumi = cmd.getJMSXPropertyNames();
while(enumi.hasMoreElements()) {
Object o = enumi.nextElement();
System.out.println("Object Type:" + o.getClass().getName());
System.out.println("Object Value:" + o);
}

QueueSession session = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
sender.send(session.createTextMessage(messageText));
System.out.println("Message Sent:" + messageText);
}



public JMSClient(String[] args) {
jndiProperties = new Properties();
if(args.length>0) {
try {
loadFromFile(args[0]);
} catch (Exception erx) {
System.err.println("Error Loading Application Properties From File:" + erx);
System.exit(1);
}
} else {
try {
loadFromResourceBundle();
System.out.println("Class:" + this.getClass().getName());
} catch (Exception erx) {
System.err.println("Error Loading Application Properties From Resource Bundle:" + erx);
System.exit(1);
}
}
System.out.println(jndiProperties);
}

private void loadFromFile(String fileName) throws Exception {
FileInputStream fis = null;
try {
fis = new FileInputStream(fileName);
jndiProperties.load(fis);
} finally {
try { fis.close(); } catch (Exception erx){}
}
}

private void loadFromResourceBundle() throws Exception {
String key = null;
String value = null;
ResourceBundle rb = ResourceBundle.getBundle("PropertiesManagement");
Enumeration enum2 = rb.getKeys();
while(enum2.hasMoreElements()) {
key = enum2.nextElement().toString();
value = rb.getString(key);
jndiProperties.put(key, value);
}
}

public void connectToJNDI() throws javax.naming.NamingException {
ctx = new InitialContext(jndiProperties);
System.out.println("Connected to " + ctx.getEnvironment().get(Context.PROVIDER_URL));
}

public void closeCtx() {
try { ctx.close(); System.out.println("Context Closed.");} catch (Exception erx){}
}

public QueueConnectionFactory lookupQueueConnectionFactory() throws javax.naming.NamingException {
return (QueueConnectionFactory)ctx.lookup(jndiProperties.get("com.nickman.neutraljms.QueueConnectionFactory").toString());
}
public Queue lookupQueue() throws javax.naming.NamingException {
return (Queue)ctx.lookup(jndiProperties.get("com.nickman.neutraljms.Queue").toString());
}

}


PropertiesManagement.properties
---------------------------------------

Code:
java.naming.provider.url=101.20.26.72:2211/TO.QMMNBS1.SVRCONN
java.naming.factory.initial=com.ibm.mq.jms.context.WMQInitialContextFactory
com.nickman.neutraljms.QueueConnectionFactory=QMMNBS1
com.nickman.neutraljms.Queue=ARS.ESB.KMS.RQI.01


Thanks in advance for support.

Regards
Bathe..
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Mar 02, 2010 9:23 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Bathe wrote:
PropertiesManagement.properties
---------------------------------------
Code:
java.naming.provider.url=101.20.26.72:2211/TO.QMMNBS1.SVRCONN
java.naming.factory.initial=com.ibm.mq.jms.context.WMQInitialContextFactory
com.nickman.neutraljms.QueueConnectionFactory=QMMNBS1
com.nickman.neutraljms.Queue=ARS.ESB.KMS.RQI.01




Your problem is in the usage of the JNDI context.
I don't consider the JNDI context you use fit for anything but for the test cases that use it.

Try the File context, using JMSAdmin...
It will behave much closer to what you may find in a J2EE server and still allow for standalone JMS...

In fact it would be my preferred approach to bind it to a J2EE context if said J2EE context does not support MQ natively... (like WAS)

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » Clustering » Connecting to Cluster Queue using JNDI
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.