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 » Convert old MQ Api code to JMS

Post new topic  Reply to topic
 Convert old MQ Api code to JMS « View previous topic :: View next topic » 
Author Message
igor.beslic
PostPosted: Mon Aug 30, 2010 6:12 am    Post subject: Convert old MQ Api code to JMS Reply with quote

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
View user's profile Send private message Visit poster's website
Vitor
PostPosted: Mon Aug 30, 2010 6:15 am    Post subject: Reply with quote

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
View user's profile Send private message
igor.beslic
PostPosted: Mon Aug 30, 2010 10:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
igor.beslic
PostPosted: Fri Dec 03, 2010 12:02 am    Post subject: Solution Reply with quote

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
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Fri Dec 03, 2010 1:53 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Convert old MQ Api code to JMS
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.