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 » JMS message to MQ from standalone Java class

Post new topic  Reply to topic Goto page 1, 2  Next
 JMS message to MQ from standalone Java class « View previous topic :: View next topic » 
Author Message
nemali
PostPosted: Wed Feb 06, 2008 7:07 pm    Post subject: JMS message to MQ from standalone Java class Reply with quote

Newbie

Joined: 06 Feb 2008
Posts: 3

I want to send a Message to MQ from stand alone Java class.

I downloaded the WMQ Initial Context related jars (MS01 MS0B).
Reading the documentation I got following questions.

1) If I change INITIAL_CONTEXT_FACTORY (to com.ibm.mq.jms.context.WMQInitialContextFactory) and PROVIDER_URL in the JMSAdmin.config file then that means my Websphere MQ cannot use any other Context factory..right?

2) Are these settings part of the server or client. Means the jars of ms01 and ms0b shd be in server of Websphere MQ or just be part of client class path?

My major concern is I am writing a 'Standalone Java Message Sender' which sends message to my Websphere MQ. This process shd not give trouble to other apps who try to send/recieve messages to my MQ server. I don’t want to disturb other Messages coming in to the server.

Thanks for your patience and time. As you can see I am new to MQ,JMS. Pls pardom my ignorance, if any.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Feb 06, 2008 8:37 pm    Post subject: Re: JMS message to MQ from standalone Java class Reply with quote

Grand High Poobah

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

nemali wrote:

I downloaded the WMQ Initial Context related jars (MS01 MS0B).
Reading the documentation I got following questions.


Don't do that. Use the file context (see using java and JMSAdmin utlities...


_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
nemali
PostPosted: Wed Feb 06, 2008 11:04 pm    Post subject: Standalone Java class sending Message to MQ Reply with quote

Newbie

Joined: 06 Feb 2008
Posts: 3

Ok.
In the case of "file context" I am confused what I shd give as PROVIDER_URL.
Is this URL point to the MQ Server physical path?
Back to top
View user's profile Send private message
jsware
PostPosted: Thu Feb 07, 2008 1:03 am    Post subject: Re: Standalone Java class sending Message to MQ Reply with quote

Chevalier

Joined: 17 May 2001
Posts: 455

nemali wrote:
Ok.
In the case of "file context" I am confused what I shd give as PROVIDER_URL.
Is this URL point to the MQ Server physical path?
Provider URL for the file-system context would be the directory where your JNDI repository will be held. Create a jmsadmin.conf file containing the following:
Code:
# WebSphere MQ JMS administration configuration file.
INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:full-path-to-jndi-repository-directory
SECURITY_AUTHENTICATION=none
I personally like to save this in the full-path-to-jndi-repository location (this is just a regular directory on your host).

Run the JMSAdmin script using "-cfg path-to-jmsadmin.conf" so that the JMSAdmin script can find your jmsadmin.conf file. Create your JNDI configurations using the various define commands.
_________________
Regards
John
The pain of low quaility far outlasts the joy of low price.
Back to top
View user's profile Send private message
JLRowe
PostPosted: Thu Feb 07, 2008 6:50 am    Post subject: Reply with quote

Yatiri

Joined: 25 May 2002
Posts: 664
Location: South East London

You don't need the JMSAdmin support pack any more, a GUI version is built into MQ explorer (if you are on v6):

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/uj10790_.htm
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Thu Feb 07, 2008 8:38 am    Post subject: Reply with quote

Grand High Poobah

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

JLRowe wrote:
You don't need the JMSAdmin support pack any more, a GUI version is built into MQ explorer (if you are on v6):

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/uj10790_.htm


Respectfully disagree. I like being able to create my context script file and creating the context from the line command redirecting the input from my script file....
And I can do this on any platform even those that will not support the MQ Explorer....

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
nemali
PostPosted: Thu Feb 07, 2008 1:19 pm    Post subject: Reply with quote

Newbie

Joined: 06 Feb 2008
Posts: 3

thanks for your inputs.
My MQ setup for local machine is working when I gave c:\jndi-dir.
But when I am trying to connect to server from the java class in my machine I am getting error.
Means, my machine is client machine.
the MQ Server is on "europa.blah.net".

then I am giving PROVIDER_URL from my machine as
PROVIDER_URL=file://europa.blah.net
Then JMSAdmin is giving me error below when I try to start from command prompt..

Initializing JNDI Context...
INITIAL_CONTEXT_FACTORY: com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL: file:\europa.blah.net
JNDI initialization failed, please check your JNDI settings and service.
For additional information on the cause of this problem run with the -v argument

Error: javax.naming.NameNotFoundException; remaining name 'C:\europa.blah.net'

C:\Program Files\IBM\WebSphere MQ\Java\bin>
Any inputs....highly appreciated.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Feb 07, 2008 1:44 pm    Post subject: Reply with quote

Grand High Poobah

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

The provider URL has nothing to do with where the MQ server is.
It just points to the directory where the file created with JMSAdmin resides.

It is the responsability of the JMSAdmin to set up the qcf / tcf in such a way that it does the right client connection...

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jsware
PostPosted: Fri Feb 08, 2008 12:21 am    Post subject: Reply with quote

Chevalier

Joined: 17 May 2001
Posts: 455

nemali wrote:
My MQ setup for local machine is working when I gave c:\jndi-dir.

then I am giving PROVIDER_URL from my machine as
PROVIDER_URL=file://europa.blah.net
Then JMSAdmin is giving me error below when I try to start from command prompt..

Initializing JNDI Context...
INITIAL_CONTEXT_FACTORY: com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL: file:\europa.blah.net
JNDI initialization failed, please check your JNDI settings and service.
For additional information on the cause of this problem run with the -v argument


Your provider URL should be:
Code:
PROVIDER_URL=file:/C:/jndi-dir
You will then need to run JMSAdmin and create a QCF and Q objects to define the MQ qmgr/objects you want to access.
_________________
Regards
John
The pain of low quaility far outlasts the joy of low price.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Feb 08, 2008 4:19 am    Post subject: Reply with quote

Grand High Poobah

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

scottj2512 wrote:
Your provider URL should be:
Code:
PROVIDER_URL=file:/C:/jndi-dir
You will then need to run JMSAdmin and create a QCF and Q objects to define the MQ qmgr/objects you want to access.

I'd go even as far as
Code:
PROVIDER_URL=file:///C:/jndi-dir

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
meenakshi.kandasami
PostPosted: Mon Jul 28, 2008 11:02 pm    Post subject: Reply with quote

Novice

Joined: 23 Jul 2008
Posts: 10

If my MQ server(which contains JNDI bindings dir) and MQ client(standalone app which sends msges to MQ) are in the different machine ...

what should be the provider_url that i should give in the client while performing JNDI look up in the above contex(file system context) so that it can point to the directory in the server
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jul 29, 2008 1:57 pm    Post subject: Reply with quote

Grand High Poobah

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

meenakshi.kandasami wrote:
If my MQ server(which contains JNDI bindings dir) and MQ client(standalone app which sends msges to MQ) are in the different machine ...

what should be the provider_url that i should give in the client while performing JNDI look up in the above contex(file system context) so that it can point to the directory in the server

Either you have rights and want to access the file across the network:
URL=file://host/pathtobindingsdirectory/
Or you don't and ftp the .bindings file to the client host:
URL=file://localhost/pathtobindingsdirectory

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rconn2
PostPosted: Wed Aug 13, 2008 11:52 am    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

Do you really need the complexity of JNDI? It's much simpler to set a connection factory directly:

Code:
   
    factory = new MQQueueConnectionFactory();

    // Binding connection - setHostName and setPort not needed.
    ...

    // Client connection setup...
    ((MQQueueConnectionFactory)factory).setHostName(sHost);
    ((MQQueueConnectionFactory)factory).setPort(iPort);

    // The following line is _necessary_ for a client connection.
    ((MQQueueConnectionFactory)factory).setTransportType
      (JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);

    ((MQQueueConnectionFactory)factory).setChannel(sChannel);
    ((MQQueueConnectionFactory)factory).setSSLCipherSuite
      (ssl_cipher_suite); 
    ((MQQueueConnectionFactory)factory).setQueueManager(sQmgr);

    // Create a QueueConnection from the QueueConnectionFactory
    connection = factory.createQueueConnection();


Some of the settings are optional... the code above is just snips. There are sample programs that show how to do this. You can just send command line args to your standalone java jms app to be used for the connection settings. Simple and straight-forward. If more complexity is needed, the java app can be called from a shell script and the args can be shell variables.
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Aug 13, 2008 1:40 pm    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

rconn2 wrote:
Do you really need the complexity of JNDI?


If you go with the code that you have above, then your program becomes WMQ JMS specific. If you want to avoid this, get your definitions out of JNDI.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
rconn2
PostPosted: Thu Aug 14, 2008 6:03 am    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

Thanks. Yes, a trade-off. At worse, a connection method can be replaced or overridden w/ a jndi based one later if support for other than wmq is ever needed.
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 » JMS message to MQ from standalone Java class
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.