Author |
Message
|
pasupulathisp |
Posted: Tue May 12, 2009 6:10 am Post subject: Remote MQ Connection |
|
|
Novice
Joined: 28 Apr 2009 Posts: 23
|
Hi,
I would like to connect to a Remote MQ running on linux.I have performed the following
1)created Queue Manager
2)created Queues
3)created channel(SYSTEM.ADMIN.SVRCONN) chltype(SVRCONN)
4)created listener
I am able to put and get messages from the queue.I am not able to connect the same with a Java code.Here is the exception :
Code: |
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
|
And how can i configure a Queue Connection factory in Linux.
Please Advice.
Thanks |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Tue May 12, 2009 6:16 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Care to share your code?
Looks like the JNDI lookup is not correct |
|
Back to top |
|
 |
zpat |
Posted: Tue May 12, 2009 6:20 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Never connect applications to ADMIN channels - create another SVRCONN channel for this purpose, and don't set the MCAUSER to MQM either!
This is not your problem but I thought I would mention it as best practise. |
|
Back to top |
|
 |
pasupulathisp |
Posted: Tue May 12, 2009 6:38 am Post subject: |
|
|
Novice
Joined: 28 Apr 2009 Posts: 23
|
Hi,
Thanks for your qucik reply.
zpat - will follow your instruction to create a different channel.
Here is the sample code which i was testing from a standalone application
Code: |
public static void main(String[] args) {
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Context jndiContext = null;
Queue queue = null;
QueueSender queueSender = null;
String queueName = "jms/testQ";
try {
Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL, "l92.34.18.54:1414/SYSTEM.ADMIN.SVRCONN");
ht.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.mq.jms.context.WMQInitialContextFactory");
jndiContext = new InitialContext(ht);
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("testQcf");
System.out.println("looked up QueueConnectionFactory: "+ queueConnectionFactory);
queue = (Queue) jndiContext.lookup(queueName);
System.out.println("looked up Queue: " + queue);
} catch (NamingException e) {
System.out.println("JNDI Problem: ");
e.printStackTrace();
}
try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender((javax.jms.Queue) queue);
TextMessage jmsMsg = queueSession.createTextMessage();
jmsMsg.setText("Hi");
queueSender.send(jmsMsg);
System.out.println("Message send");
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
System.out.println("Closing Connection");
queueSession.close();
queueConnection.close();
} catch (Exception e) {
}
}
}
|
I am not sure how to get the connection factory.Can you please tell me how to create the qcf.i guess i have not created it right and also can we get the connection by queue lookup.
Thanks |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Tue May 12, 2009 7:06 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
|
Back to top |
|
 |
pasupulathisp |
Posted: Tue May 12, 2009 7:22 am Post subject: |
|
|
Novice
Joined: 28 Apr 2009 Posts: 23
|
Hi WMBDEV1,
Thanks for your response.
Yes,i missed the creation of JMS objects.I was following the same link which you have specified.But i have some exception while running the JMSADMIN script,which i came across.
I am having security authentication failure.I am not sure how/where to define the security credentials.
Thanks |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Tue May 12, 2009 7:26 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Are you running the script as mqm? |
|
Back to top |
|
 |
pasupulathisp |
Posted: Tue May 12, 2009 7:34 am Post subject: |
|
|
Novice
Joined: 28 Apr 2009 Posts: 23
|
Hi,
i am having exception when i am trying to connect to Remote MQ.So,the exception is from Standalone App.But i was running all the scripts as mqm.
Code: |
WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2035' ('MQRC_NOT_AUTHORIZED').
|
So,i should be defining the security credential in my standalone app.I am not sure where these security credential fit into. |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Tue May 12, 2009 7:49 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
By default the Java app will connect with the user it is being run as.
You will need to use the setmqaut on the QM to allow this user to access it.
I normally grant permissions to the channel, queue and QM for the user.
Also, if its just for test you can add mqm to the MCA on the channel being used but you really shouldnt do this past development environments. |
|
Back to top |
|
 |
bruce2359 |
Posted: Tue May 12, 2009 8:03 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Quote: |
Also, if its just for test you can add mqm to the MCA on the channel being used but you really shouldnt do this past development environments. |
I, on the other hand, never grant authorizations in test that are different from those that will exist in QA and PROD. MQM group, especially. Once granted, it's difficult to take away. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
pasupulathisp |
Posted: Tue May 12, 2009 8:10 am Post subject: |
|
|
Novice
Joined: 28 Apr 2009 Posts: 23
|
Thanks for all the information. I really appreciate your help and knowledge sharing.
 |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue May 12, 2009 8:43 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
As well as passing the userid to the connection on stand alone client connected JMSApp look into
Code: |
qcf.createConnection(username, dummypwdstring); |
And by the way the JNDI provider you are using is a direct pass through to the qmgr and is not best practice.
Try the file base JNDI first. It will be easier to understand...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|