|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Convert old MQ Api code to JMS |
« View previous topic :: View next topic » |
Author |
Message
|
igor.beslic |
Posted: Mon Aug 30, 2010 6:12 am Post subject: Convert old MQ Api code to JMS |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Hi, my intention is to convert this peace of code:
Code: |
log.debug("MQ211HI03: retrieving prices from MQ...");
// subscription
final String pricesTopicStr = "FEED/*";
int openOptionsForGet = CMQC.MQSO_CREATE | CMQC.MQSO_FAIL_IF_QUIESCING
| CMQC.MQSO_WILDCARD_CHAR | CMQC.MQSO_MANAGED | CMQC.MQSO_NON_DURABLE;
MQQueueManager qm = getMQManager(mq.getQueueManagerIn());
MQDestination destinationForGet = qm.accessTopic(pricesTopicStr, null,
CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, openOptionsForGet);
MQGetMessageOptions mgmo = new MQGetMessageOptions();
mgmo.options = CMQC.MQGMO_WAIT;
mgmo.waitInterval = 1;
do {
MQMessage messageForGet = new MQMessage();
try {
destinationForGet.get(messageForGet, mgmo);
String poruka = messageForGet.readLine();
String errorCode = poruka.substring(17, 24).trim();
log.debug("MQ211HI04A: Topic from MQ with errorcode: " + errorCode);
} catch (com.ibm.mq.MQException e) {
if (e.reasonCode == 2033) {
log.debug("MQ211HI04: Data collected from MQ.");
log.debug("MQ211HI05: Closing MQ...");
destinationForGet.close();
qm.close();
log.debug("MQ211HI06: MQ closed...");
// timeout - all topics red
// rezultat
return mqPrices;
} else {
throw e;
}
}
} while (1 == 1);
|
to JMS (provider independent code).
For now, in JMS spirit I succeeded to read from topic BUT just one message. Old code reads content from almost 400 TOPICS covered with wildcard, but JMS code just content from one topic.
Thanks! |
|
Back to top |
|
 |
Vitor |
Posted: Mon Aug 30, 2010 6:15 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Is this the same set up as here? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
igor.beslic |
Posted: Mon Aug 30, 2010 10:47 pm Post subject: |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Yes, that post refer to connection factory setup. (maybe it is important to say that publisher published messages to topics with option DeliveryMode.PERSISTENT) |
|
Back to top |
|
 |
igor.beslic |
Posted: Fri Dec 03, 2010 12:02 am Post subject: Solution |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Hi, solution follows. This example reads messages from all topics selected by expression "FEED/+". (Also, publisher published messeges as persistent messages so reader gets all unreaded messages):
Code: |
@Resource(mappedName="java:/wmqTCF")
private TopicConnectionFactory wmqTCF;
...
...
log.debug("MQ211HI03: retrieving prices from MQ...");
// subscription
final String pricesTopicStr = "FEED/+";
try {
TopicConnection tc = wmqTCF.createTopicConnection();
tc.start();
TopicSession ts = tc.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
Topic feedTopic = ts.createTopic(transTopicStr);
TopicSubscriber subscriber = ts.createSubscriber(feedTopic);
Message jmsMessage = null;
try {
while(true){
jmsMessage = subscriber.receive(100);
if(jmsMessage instanceof TextMessage){
String msgContent = ((TextMessage)jmsMessage).getText();
log.debug("MQ214R0I04A: Received "+msgContent);
}
}
} catch (Exception e) {
log.error("MQ214HE02: "+e.getMessage());
e.printStackTrace();
}
tc.close();
} catch (JMSException e) {
log.error("MQ214HE01: "+e.getMessage());
}
|
Note:
1. * changes to +
2. each while itration reads one topic in FEED/+
3. in catch clause timeout exception signals no messages available
|
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Dec 03, 2010 1:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Bad practice on the JMSException not to attempt to retrieve the linked Exception (provider exception)  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|