Author |
Message
|
jshailes |
Posted: Mon May 18, 2009 2:38 pm Post subject: MQ? JMS? Baffled! |
|
|
Apprentice
Joined: 18 May 2009 Posts: 31
|
Hi.
How can I make a JMS J2SE app to receive messages from an existing queue? I am running MQ 7.
So far I have created:
- queue manager = QMGR1
- listener = LSTR1
- receiver channel = CHL1
- queue = Q1
The queue contains messages. When I run 'amqsget Q1' I can receive messages. I have followed instructions on tinyurl/simplejms (apologies for lack of com!) but to no avail. I receive the following error:
JMSWMQ0018: Failed to connect to queue manager 'QMGR1' with connection mode 'Client' and host name 'localhost'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
The code I've followed is below.
Thanks.
James
Code: |
public class SimplePTP {
public static void main(String[] args) {
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
// Config
cf.setHostName("localhost");
cf.setPort(15001);
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setQueueManager("QMGR1");
cf.setChannel("CH1");
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///Q1");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);
MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
JMSTextMessage message = (JMSTextMessage) session.createTextMessage("SimplePTP "+ uniqueNumber);
// Start the connection
connection.start();
sender.send(message);
System.out.println("Sent message:\\n" + message);
JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
System.out.println("\\nReceived message:\\n" + receivedMessage);
sender.close();
receiver.close();
session.close();
connection.close();
System.out.println("\\nSUCCESS\\n");
}
catch (JMSException jmsex) {
System.out.println(jmsex);
System.out.println("\\nFAILURE\\n");
}
catch (Exception ex) {
System.out.println(ex);
System.out.println("\\nFAILURE\\n");
}
}
} |
[/quote] |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Mon May 18, 2009 3:39 pm Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Can you connect other client applications (like RFHUTIL?)
Is the listener started? |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 18, 2009 11:41 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Moved to correct section _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 18, 2009 11:47 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
WMBDEV1 wrote: |
Can you connect other client applications (like RFHUTIL?) |
RFHUtil isn't a client application - RFHUtilc is.
jshailes - the apparently pedantic distinction I've made above is the source of your problems. There are 2 kinds of connection to a queue manager, amqsget makes one kind, your Java is attempting the other. If you run the sample amqsgetc it will probably fail in the same way your code does.
What you need to do is follow the instructions given in the Clients manual to configure the queue manager for a client connection. You can test your efforts with amqsgetc; when that works, try your Java again.
Tip - change your code to capture the linked exception from the JMS error. The JMS errors are generic and almost useless, the linked exception contains the WMQ reason code, which is fairly specific.
Unless it's 2059!  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jshailes |
Posted: Tue May 19, 2009 8:24 am Post subject: |
|
|
Apprentice
Joined: 18 May 2009 Posts: 31
|
Hi Vitor. Many thanks for your reply. I've spent the day trying to make amqsgetc work but receive an error message stating libmqic_r.so doesn't exist:
/opt/mqm/samp/bin/amqsgetc: error while loading shared libraries: libmqic_r.so: cannot open shared object file: No such file or directory
I've searched the disk for such a file and there definitely isn't one there.
I've seen online that there is a separate installation for the client software, would this be required?
Cheers,
James |
|
Back to top |
|
 |
Vitor |
Posted: Tue May 19, 2009 9:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
jshailes wrote: |
I've seen online that there is a separate installation for the client software, would this be required? |
Pretty much. Client connections rather rely on the client software....
All the clients are available as support pacs for free download, assuming it's not included on the installation media your server side software was installed on.
Remember my advice to configure the client connection; just installing the software isn't enough. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jshailes |
Posted: Tue May 19, 2009 9:21 am Post subject: |
|
|
Apprentice
Joined: 18 May 2009 Posts: 31
|
OK, apologies for that then, I thought all of the client software was installed when I set up MQ Server.
What do you actually mean when you say configure the client connection? I have tried to find documentation/tutorials on how to set up a client connection but they never seem to be very simple!
The existing queue is populated from another company's MQ Server, using IPT and a listener/receiver channel. The messages are stored on Q1. I'm kind of guessing now, but the client will:
a. connect to the same queue manager on the server
b. pick messages up from the the same queue (Q1)
c. in order to find Q1 a sender channel is required?
Is any of that correct?! I feel like mq is throwing my common sense out the window, I'm sure there's something fundamental I'm missing.
Cheers guys.
James |
|
Back to top |
|
 |
Vitor |
Posted: Tue May 19, 2009 1:15 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
jshailes wrote: |
I have tried to find documentation/tutorials on how to set up a client connection but they never seem to be very simple! |
WMQ isn't the most straightforward product in the world, but you are comfortably in the simple part. As I indicated above, the Clients manual will tell you everything you want to know.
jshailes wrote: |
a. connect to the same queue manager on the server |
jshailes wrote: |
b. pick messages up from the the same queue (Q1) |
jshailes wrote: |
c. in order to find Q1 a sender channel is required? |
Sender channel is on the other end of the receiver channel you're using. You need a server connection channel at least. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jshailes |
Posted: Tue May 19, 2009 3:26 pm Post subject: |
|
|
Apprentice
Joined: 18 May 2009 Posts: 31
|
Right ok, sounds like you can only 'send' server-server. Kinda makes sense. I don't mean to be obtuse but I'm not sure I've ever been able to find the client manual, can I be rude and ask you where I can find it? Probably ought to expect a lmgtfy.com link!!
So as I see it now:
Create a QMGR = QMGR1
Create a Receiver Channel (if you are to receive messages from someone else) = CHL1
Create Listener (as above - only if you are receiving messages from someone else) = LSTR1
Create a Queue for the messages to be stored on = Q1
Then to communicate via JMS with the queue:
Create a server connection channel = CHL2
This server connection channel allows JMS to connect as a client. The code to do this is:
Code: |
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName("localhost");
cf.setPort(1414);
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setQueueManager("QMGR1");
cf.setChannel("SYSTEM.DEF.SVRCONN");
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///Q1");
|
|
|
Back to top |
|
 |
fjb_saper |
Posted: Tue May 19, 2009 8:52 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Your code looks pretty much right. Looks to me like you missed a jar on the import path or are willfully going the proprietary and non compatible way:(always casting to the implementing MQ object.
You need jta.jar and jms.jar for the relevant javax.jms.* and Transaction manager classes on the classpath. Make it easy on yourself and put all jar files from <MQinstall>/java/lib on the classpath.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Tue May 19, 2009 11:39 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
jshailes wrote: |
can I be rude and ask you where I can find it? |
All the manuals (including the Clients manual) are in the IBM infocentre. You'll find a link at the top of this page, along with a link to some sample code you might find useful. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|