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 » IBM MQ Java / JMS » Making connection via JNDI?

Post new topic  Reply to topic Goto page 1, 2  Next
 Making connection via JNDI? « View previous topic :: View next topic » 
Author Message
viki
PostPosted: Wed Mar 01, 2006 1:51 am    Post subject: Making connection via JNDI? Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

Right now I'm making a connection @ runtime, like this:
Code:

MQQueueConnectionFactory factory=null;

factory = new com.ibm.mq.jms.MQQueueConnectionFactory();
factory.setQueueManager("myQMGR");
factory.setHostName("myHost");
factory.setPort("myPort");
factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
factory.setChannel("SYSTEM.DEF.SVRCONN");
       
QueueConnection connection=factory.createQueueConnection();


Now, I want to implement the same above via JNDI. For familiarity with JNDI, I have creted a class which uses JNDI to make connection with local harddisk. Which is:
Code:

 String name = "d:\\";
      // Here we use the file system service provider
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");

      try {
         // Create the initial context
         Context ctx = new InitialContext(env);

         // Look up an object
         Object obj = ctx.lookup(name);
        System.out.println(name + " is bound to: " + obj);
         ctx.close();
      } catch (NamingException e) {
         System.err.println("Problem looking up " + name + ": " + e);
      }


It'll be great if someone could guide me here. What neccessary steps I have to take in order to make connection via JNDI? Remember, this connection is b/w the client and the server running IBM WebSphere MQ V5.3.

Thanks in advance.

Bye,
Viki.
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 2:11 am    Post subject: Re: Making connection via JNDI? Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

Did you take a look at the JMSPubSub.java sample program that's included in an MQ installation? It might have some of the answers you're looking for.
Back to top
View user's profile Send private message
viki
PostPosted: Wed Mar 01, 2006 2:20 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,
Ok, I've seen JMSPubSub.java. And here is the code which I saw:
Code:

String CTX_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
String INIT_URL    = "ldap://polaris/cn=PubSub,o=ibm_us,c=us";

        Hashtable env = new Hashtable();
        env.put( Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY );
        env.put( Context.PROVIDER_URL, INIT_URL );
        env.put( Context.REFERRAL, "throw" );
        Context ctx = new InitialDirContext( env );

        // Obtain the TopicConnectionFactory from JNDI
        TopicConnectionFactory tcf =
                       (TopicConnectionFactory)ctx.lookup( "cn=PubSub.TCF" );


My question is: What will be the CTX_FACTORY and INIT_URL in my case? Since, I'm not using LDAP? Do I need to install WebSphere Application Server for this purpose? Also, where I'll specify the IP Address and Port of the server running MQ?

Bye,
Viki.
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 2:26 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

If not LDAP, then what are you using?
Back to top
View user's profile Send private message
viki
PostPosted: Wed Mar 01, 2006 2:33 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,
The connection code which I sent in very 1st post is used to connect the client with the server running MQ V5.3. Client also has the same MQ V5.3 installed. The job of the client is to send/transfer a file to the server and recieve it back.

Apart from MQ V5.3, I'm not using any other software. In other words, only MQ V5.3 is installed on clean Win 2003 OS.

Bye,
Viki.
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 2:44 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

viki wrote:
The job of the client is to send/transfer a file to the server and recieve it back.

Apart from MQ V5.3, I'm not using any other software. In other words, only MQ V5.3 is installed on clean Win 2003 OS.

OK, so requirement 1 is "send file from client to server and receive it back". It sounds like you can do what you want easily with an MQ client possibly using a request/reply messaging model, which is good news so far. Please say again where JNDI comes into your requirements.
Quote:
What neccessary steps I have to take in order to make connection via JNDI?

This point in your original post needs to be clarified - please say exactly what part you expect JNDI to play in your system.
Back to top
View user's profile Send private message
viki
PostPosted: Wed Mar 01, 2006 3:17 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

Sending file (in fact file contents) from client to the server and recieving it back is done successfully. What I'm expecting from JNDI is this:

Right now, I'm declaring IP Address and Port # of the server in the code, which is in fact a hard-code. Instead of doing this, I want to declare this information (IP and Port#) in a file (txt, xml whatever) and from that file my code read on runtime this information and do the connection.

Well, I guess, after explaining you the above para, I've find my answer . I can save this info in any txt file and my java code will:
- read this file.
- fetch the information IP and Port.
- save the info is corresponding variables.
- pass the variables for making connection (see my 1st post - 1st code)

I guess, here I do not need JNDI. This could be done simply as stated above.

Bye,
Viki
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 3:31 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

viki wrote:
I guess, here I do not need JNDI. This could be done simply as stated above.

OK I think I was slow to understand what you were saying - sorry about that. After a bit of searching I found this: http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/jmscfg.htm

One can use the JMSAdmin tool, and store the connection info in a local file. This appears related to JNDI because the class mentioned is com.sun.jndi.fscontext.RefFSContextFactory

There's a sizeable section on this at http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/jms77h1.htm

Regards
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Mar 01, 2006 3:47 am    Post subject: Reply with quote

Grand High Poobah

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

Viki here is some sample code

Code:

        CTX_FACTORY="com.sun.jndi.fscontext.RefFSContextFactory";
        INIT_URL="file:///C:/jndi";
        //"file://host/directory_to_the_.bindings_file";
        Hashtable env = new Hashtable();
        env.put( Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY );
        env.put( Context.PROVIDER_URL, INIT_URL );
        env.put( Context.REFERRAL, "throw" );
        Context ctx = new InitialDirContext( env );

        // Obtain the TopicConnectionFactory from JNDI
        TopicConnectionFactory tcf =
                       (TopicConnectionFactory)ctx.lookup( "mytopic" );
        //same as defined in the JMSAdmin

       //obtain the qcf
       QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("myqcf");
       //myqcf has to have been defined in JMSAdmin

      // lookup queue
      Queue myqueue = (Queue) ctx.lookup("myqueue");


Of course all objects need to exist and be defined to the context using the JMSAdmin tool.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
viki
PostPosted: Wed Mar 01, 2006 4:27 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

Never worked with JMS Admin Tool. Let me give it a try and I'll get to you back..

Bye,
Viki.
Back to top
View user's profile Send private message
viki
PostPosted: Wed Mar 01, 2006 6:46 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,
I have created javax.jms.QueueConnectionFactory with the JNDI name SampleQCF and a javax.jms.Queue named SampleQueue, using the following script (on JMSAdmin.bat)
Code:

InitCtx> DEFINE CTX(myCtxt2)
InitCtx> CHANGE CTX(myCtxt2)
InitCtx/myCtxt2> def qcf(SampleQCF) qmgr(QMMGR) tran(client) chan(SYSTEM.DEF.SVRCONN) host(localhost) port(1414)

InitCtx/myCtxt2> def q(SampleQueue) qmgr(QMGR) qu(SAMPLE.QUEUE)
InitCtx/myCtxt2> DISPLAY CTX

Connection is successfull.
But the new queue, SAMPLE.QUEUE is not created in the WebSphere MQ Explorer, under Console Root\WebSphere MQ\Queue Managers\QMGR\Queues. Therefore, when I try to create queue using
Code:
session.createQueue("queue:///"+Constants.QUEUE_NAME+"?targetClient=1");

I get the exception:
Exeption javax.jms.InvalidDestinationException: MQJMS2008: failed to open MQ queue queue://QMGR/SAMPLE.QUEUE

What is wrong here? I guess, I've created the queue (using JMSAdmin tool) in context myCtxt2. Whereas, WebSphere MQ Explorer uses some another/different conext to lookup the queue's?

Bye,
Viki.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Mar 01, 2006 7:12 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

viki wrote:
What is wrong here? I guess, I've created the queue (using JMSAdmin tool) in context myCtxt2. Whereas, WebSphere MQ Explorer uses some another/different conext to lookup the queue's?


Yep.

You have to also create the queue in the queue manager. The JMSAdmin tool merely creates a reference to a queue.

So just use MQ Explorer and create a new local queue with the right name.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
viki
PostPosted: Wed Mar 01, 2006 7:42 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

jefflowrey wrote:
You have to also create the queue in the queue manager. The JMSAdmin tool merely creates a reference to a queue.

So just use MQ Explorer and create a new local queue with the right name.


So what is the use of JMS Admin Tool? if we've to create queue manually via MQ Explorer?

Bye,
Viki
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Mar 01, 2006 9:05 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

viki wrote:
So what is the use of JMS Admin Tool? if we've to create queue manually via MQ Explorer?


It creates the bindings in the JNDI directory, which is completely separate from the MQ environment.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 9:06 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

MQ Explorer administers a queue manager, but not apps. JMSAdmin is a tool to generate app configuration info that can be read at runtime by apps that need it.

The essential difference is that one controls the queue manager, and the other controls the app(s).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Making connection via 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.