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 » MQ in WebSphere, need advise

Post new topic  Reply to topic
 MQ in WebSphere, need advise « View previous topic :: View next topic » 
Author Message
mq_novice
PostPosted: Mon Jun 26, 2006 11:59 am    Post subject: MQ in WebSphere, need advise Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

Hi. I'm extremely new to MQ and all and not entirely sure where to look at.
I have a Stateless Session EJB in WebSphere that does nothing but putting a message to a queue.

So every single time, It creates the QWriter class (the class I created),

Opens the queue,

Code:

MQEnvironment mq = new MQEnvironment();
MQEnvironment.hostname = hostname;
MQEnvironment.port = port;
MQEnvironment.channel = channel;
MQEnvironment.disableTracing();
MQQueueManager qMgr = new MQQueueManager("test.queue.manager");

int openOption = MQC.MQOO_BROWSE | MQC.MQOO_INPUT_SHARED | MQC.MQOO_OUTPUT;
MQQueue queue = qMgr.accessQueue("TEST.QUE", openOption, null, null, null);


and puts the message

Code:

MQMessage mqMessage = new MQMessage();
mqMessage.writeString(message);
queue.put(mqMessage);


and then disconnect

Code:

if (queue != null && queue.isOpen()) {
  queue.close();
  queue = null;
}

if (qMgr != null && qMgr.isConnected()) {
  qMgr.disconnect();
  qMgr = null;
}



As you can guess, it's probably very wasteful in resource. My question is,
Can somebody point me to the using Connection Pool (in WebSphere)? Is there better way to do above (milliion times a day...), some sample code?

Again, I'm very new to MQ and right now, I have no clue where to look...
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Jun 26, 2006 2:45 pm    Post subject: Reply with quote

Grand High Poobah

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

How about looking at the JMS API instead of the base API?
Pooling will be automatic.
You will need to define your resource(MQ manager) in JNDI though...

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
8davitt
PostPosted: Tue Jun 27, 2006 1:49 am    Post subject: Reply with quote

Apprentice

Joined: 06 Feb 2003
Posts: 37
Location: Seated in front of monitor

Connection pooling is available for MQ Java API and it is clearly documented in the Using Java manual. However I will not give a reference to that information because as fjb_saper has indicated you should be using the JMS API.

If you are using EJBs and J2EE the preferred messaging API is JMS.

/s
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 5:28 am    Post subject: thanks Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

Thanks for all you replies. I also found out that I should look into JMS.. I'm using WebSphere Studio v5 and need to connect to IBM MQ...
basically, (as you already noticed from above)
Connect to MQ (could be on different machine),
Put messages into the queue

I'm all confused on peer-to-peer and Publish/Subscribe...
which way should I choose? or which one is for me?

also can anybody point to where I can found more information on what to set up in WebSphere Studio ?

so lost...
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jun 27, 2006 5:39 am    Post subject: Re: thanks Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mq_novice wrote:

I'm all confused on peer-to-peer and Publish/Subscribe...
which way should I choose? or which one is for me?



A question with as many answers as people to ask the question of. If not more....

It really comes down to what you're trying to achieve, what your topology is, what messages are you moving round, etc, etc, etc. There really is no single good answer (which is why both functions still exist within the product of course)

I seriously doubt that's helped you! Read (or re-read) the Intercommunication manual and draw comfort from the fact that no matter if you're using peer-to-peer or pub/sub you'll still need to connect to a queue manager & put a message so no work is wasted....

(Mind you, that's not to say exactly the same code works for both.... )
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 6:19 am    Post subject: that's why I'm confused... Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

I'm looking at many examples but none of them illustrate how I can connect ot the QUEUE in IBM MQ Server. Many tutorials talk about P2P or Pub/Sub, sending messages and receiving messages but I just need to put the messages into QUEUE in some remote WebSphere MQ server...
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jun 27, 2006 6:26 am    Post subject: Re: that's why I'm confused... Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mq_novice wrote:
I'm looking at many examples but none of them illustrate how I can connect ot the QUEUE in IBM MQ Server. Many tutorials talk about P2P or Pub/Sub, sending messages and receiving messages but I just need to put the messages into QUEUE in some remote WebSphere MQ server...


Well pedantically you don't connect to a queue you connect to a queue manager but that's not important right now.

Even this requirement has a number of ways of fulfillng it. You could (in theory at least) client onto the remote queue manager and put the message, publish the message via a broker to a subscriber on the remote queue manager, put the message into a remote queue on the local queue manager, ...

As I said before it depends on requirements and topology. Is there an existing set-up that you're trying to add to? You're probably best served by finding out what the prevalant method is and cribbing some code. You already have a functioning (if inefficient) prototype that you can smarten with some connection pooling.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 7:45 am    Post subject: yes. Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

Thans for the reply Vitor. yes.. I have the code that's not using Connection pooling or any kind.. just MQJAVA connect to remote MQ server, drop the message into the queue.

It's fairly simply operation, so I am thinking about using P2P...
I've been looking / reading IBM documentation and trying to find / learn more about it.

So my guess would be, I could just use P2P style, connect to remote queue manager and drop the message into the queue... am I right?

now, that's what I am trying to find out... setting up JNDI and all those above that I need...

thanks!
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jun 27, 2006 8:04 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

If it's that simple then yes P2P is probably as much as you need. The options are to connect as you suggest to the remote queue manager and do a put (more of a point than a point-to-point! ) or connect to a local queue manager and use a remote queue.

The last presupposes that you have a local and a remote queue manager; sounds a bit like a test set-up at your end.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 8:40 am    Post subject: trying to set up examples Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

thanks for your reply.

I'm still looking at the examples from IBM.. since I am using WebSphere Studio V5 and IBM Websphere MQ...

However, the documentation keeps mentioning using JMSAdmin to set up JNDI and etc... do you (or anybody) know how to set this up in the WebSphere server? what is needed to be set up in WebSphere?

hmmm still much confused...

the scrip that I'm supposed to run with JMSAdmin looks like this

Code:

def ctx(mq)
chg ctx(mq)
def qcf(MyQCF) qmgr(QM1)
def q(MyQueue) qmgr(QM1) queue(Q1)
end


the explantion follow...

Quote:

The first line creates a context named mq. The next line changes to the mq context so that all subsequent commands are relative to that context. Then, a QueueConnectionFactory is created with the JNDI name MyQCF. This QueueConnectionFactory is configured to work with the QM1 queue manager that we defined in WebSphere MQ. Next, a Queue object is created with the JNDI name MyQueue, and is configured to work with the Q1 queue on QM1 that we defined in WebSphere MQ. Finally, an end command is issued to shut down JMSAdmin.

Note that the name of the context created and the names of the administered objects are my own invention -- there's nothing special or mandatory about those names. I could have given them completely different names and the sample applications would still work, as you will see later.



Why can't I just set up something in WebSphere App Server and use that like JDBC?

hmm... I am much more familiar with MQ now than yesterday but still very confused...
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jun 27, 2006 10:33 am    Post subject: Re: trying to set up examples Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mq_novice wrote:


Why can't I just set up something in WebSphere App Server and use that like JDBC?



Because it just doesn't work like that?

You have fun with the manuals and the experimentation now. 6 months down the line, you'll look back on these early faltering steps and laugh out loud.

(Or start laughing hysterically as they carry you off to a secure institution. I may just be projecting my own expereinces there)
_________________
Honesty is the best policy.
Insanity is the best defence.


Last edited by Vitor on Tue Jun 27, 2006 11:12 pm; edited 1 time in total
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 11:37 am    Post subject: for now... Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

yes.. I am sure that I will...

but I'm really frustrated right now...

Code:

InitialContext initContext = new InitialContext();
Context environment = (Context)initContext.lookup("java:comp/env");
QueueConnectionFactory connectionFactory = QueueConnectionFactory)environment.lookup("myQCF");


but I get the error...

MQBean: Name "myQCF" not found in context "java:comp/env".

I defined myQCF in
Admin Console
- WebSphere MQ JMS Provider
- WebSphere MQ Queue Connection Factories

so confused...
Back to top
View user's profile Send private message
mq_novice
PostPosted: Tue Jun 27, 2006 12:01 pm    Post subject: finally got it.. Reply with quote

Novice

Joined: 26 Jun 2006
Posts: 13

thanks all for your help and replies...

finally got it..

my first mq app is working after I get rid of the below line...

Context environment = (Context)initContext.lookup("java:comp/env");

and looking up with InitialContext...

QueueConnectionFactory connectionFactory = QueueConnectionFactory)initContext.lookup("myQCF");


Many thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » MQ in WebSphere, need advise
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.