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 » General Discussion » MQ Java Triggered server example

Post new topic  Reply to topic
 MQ Java Triggered server example « View previous topic :: View next topic » 
Author Message
mayel
PostPosted: Wed Sep 03, 2003 1:36 pm    Post subject: MQ Java Triggered server example Reply with quote

Newbie

Joined: 03 Sep 2003
Posts: 6
Location: colorado springs CO USA



I am looking for a MQ Java Triggered server example. Does anyone have a sample program they can share with me? The more basic the better, so long as it is compleate and functioning.
_________________
Best Regards,
Mayel ><>
Back to top
View user's profile Send private message AIM Address
RogerLacroix
PostPosted: Thu Sep 04, 2003 8:31 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Sure, as long as you're going to share your pay-check.

Any program can be triggered, including a standard MQ/Java application. Look in the repository above under Java or go to my site at:
http://www.capitalware.biz/sample_mqseries.html#javacode
and download a "complete" MQ/Java program.

later
Roger...
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
mayel
PostPosted: Fri Sep 05, 2003 7:57 am    Post subject: Reply with quote

Newbie

Joined: 03 Sep 2003
Posts: 6
Location: colorado springs CO USA

Roger,

I will look in to it, thank you. Now what I am wondering about is: other then starting the java program via a script. How can I set the CLASSPATH for example?

Also I saw in the WEBSphere MQQueue java class methods such as:
getTriggerControl, getTriggerData, getTriggerDepth, etc. And I have read information in some other place in this BBS about a Process Definition object. All of these pieces lead me to believe I am missing something. Perhaps there is some other methog?

Best Regards,
_________________
Best Regards,
Mayel ><>
Back to top
View user's profile Send private message AIM Address
RogerLacroix
PostPosted: Fri Sep 05, 2003 8:47 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Those methods allow you to inquire on a queue about its attributes (TRIGGER, TRIGDATA & TRIGDPTH). You set these attributes using the DEFINE or ALTER MQSC commands. These attributes control how and when your program will be trigger.

From an application program point of view, you would rarely use these.

If you know what queue your application needs to read once it is trigger then your application is good to go. But if your application is set to be triggered by more than one queue then you can read and parse the MQTMC2 structure. It is passed to your program as the first input argument. (i.e. args[0]) Just extract what you need. (i.e. queue name)

later
Roger...
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
mayel
PostPosted: Mon Sep 08, 2003 7:56 am    Post subject: Reply with quote

Newbie

Joined: 03 Sep 2003
Posts: 6
Location: colorado springs CO USA

ah, that compleates the picture! Thank you again =)
_________________
Best Regards,
Mayel ><>
Back to top
View user's profile Send private message AIM Address
clindsey
PostPosted: Mon Sep 08, 2003 8:53 am    Post subject: Reply with quote

Knight

Joined: 12 Jul 2002
Posts: 586
Location: Dallas, Tx

Here is a sample for you. Now you can share your paycheck with both Roger and me.

Charlie

Code:


import java.io.*;
import java.lang.*;
import com.ibm.mq.*;



class MQTrigger
{

   private String structId;
   private String version;
   private String qName;
   private String processName;
   private String triggerData;
   private String applType;
   private String applId;
   private String envData;
   private String userData;
   private String qMgrName;

   

   /******************************************************/
   /* Constructor to parse the TMC stucture and set      */
   /* the class attributes.                              */
   /* Values derived from cmqc.h                         */
   /******************************************************/
   public MQTrigger(String tmcStruct) throws StringIndexOutOfBoundsException
   {

      structId    = tmcStruct.substring(0,3).trim();
      version     = tmcStruct.substring(4,8).trim();
      qName       = tmcStruct.substring(8,55).trim();
      processName = tmcStruct.substring(56,103).trim();
      triggerData = tmcStruct.substring(104,167).trim();
      applType    = tmcStruct.substring(168,171).trim();
      applId      = tmcStruct.substring(172,427).trim();
      envData     = tmcStruct.substring(428,555).trim();
      userData    = tmcStruct.substring(556,683).trim();

      /************************************************/
      /* A TMC version 2 structure includes the       */
      /* queue mananger name which is not present in  */
      /* a version 1 structure                        */
      /************************************************/
      if (version.compareTo(new String("2")) == 0)
      {
         qMgrName = tmcStruct.substring(684,730).trim();
      }
      else
      {
         qMgrName = "";
      }
   }

   public String getStructId()
   {
      return(structId);
   }

   public String getVersion()
   {
      return(version);
   }


   public String getQueueName()
   {
      return(qName);
   }

   public String getProcessName()
   {
      return(processName);
   }

   public String getTriggerData()
   {
      return(triggerData);
   }

   public String getApplicationType()
   {
      return(applType);
   }

   public String getApplicationId()
   {
      return(applId);
   }

   public String getEnvironmentData()
   {
      return(envData);
   }

   public String getUserData()
   {
      return(userData);
   }

   public String getQueueManagerName()
   {
      return(qMgrName);
   }

};

public class JavaTrigger
{


   private MQQueueManager qMgr;

   public static void main (String args[]) throws IOException
   {
      if (args.length < 1)
      {
         System.out.println("This must be a triggered application");
      }
      else
      {
         System.out.println("MQGet: browse and optionally get messages");
         JavaTrigger jt = new JavaTrigger();
         jt.start(args);
      }
      System.exit(0);
   }


   public void start(String args[])
   {
      try
      {

         /******************************************************/
         /* Create a MQTrigger class object to read the TMC    */
         /* structure into the correct attribute.              */
         /******************************************************/
         MQTrigger tmc = new MQTrigger(args[0]);



         /******************************************************/
         /* Connect to the queue manager identified by the     */
         /* trigger.                                           */
         /******************************************************/
         
         qMgr = new MQQueueManager(tmc.getQueueManagerName());

         /******************************************************/
         /* Open the queue identified by the trigger.          */
         /******************************************************/
         
         int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;

         MQQueue triggerQueue = qMgr.accessQueue(tmc.getQueueName(),
                                                 openOptions,
                                                 null, null, null);

         /******************************************************/
         /* Set up our options to get the first message        */
         /* Wait 5 seconds to be cetain all messages are      */
         /* processed.                                         */
         /******************************************************/
         MQGetMessageOptions gmo = new MQGetMessageOptions();
         gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_CONVERT;
         gmo.waitInterval = 5000;

         MQMessage triggerMessage = new MQMessage();

         /*****************************************************/
         /* Read each message from the queue until there are  */
         /* no more messages to get.                          */
         /*****************************************************/
         long rc = 0;
         do
         {
            rc = 0;
            try
            {
               /***********************************************/
               /* Set the messageId and correlationId to none */
               /* to get all messages with no message         */
               /* selection.                                  */
               /***********************************************/
               triggerMessage.clearMessage();
               triggerMessage.correlationId = MQC.MQCI_NONE;
               triggerMessage.messageId = MQC.MQMI_NONE;

               triggerQueue.get(triggerMessage, gmo);
               String msg = triggerMessage.readString(triggerMessage.getMessageLength());

               /***********************************************/
               /* Insert business logic for the message here. */
               /* For this sample, echo the message             */   
              /***********************************************/
               System.out.println("Message: " + msg);

            }
            catch (MQException mqEx)
            {
               rc = mqEx.reasonCode;
               if (rc != MQException.MQRC_NO_MSG_AVAILABLE)
               {
                  System.out.println("Get Message failed with rc = " 
                                     +  rc);
               }
            }
            catch (Exception ex)
            {
               System.out.println("Generic exception: " + ex);
               rc = 1;
            }

         } while (rc == 0);


         /**********************************************************/
         /* Cleanup MQ resources prior to exiting.                 */
         /**********************************************************/
         triggerQueue.close();
         qMgr.disconnect();
      }

      catch (MQException mqEx)
      {
         System.out.println("MQ failed with completion code = "
                            + mqEx.completionCode
                            + " and reason code = " + mqEx.reasonCode);
      }
   }

}

Back to top
View user's profile Send private message
mayel
PostPosted: Thu Sep 11, 2003 1:03 pm    Post subject: Reply with quote

Newbie

Joined: 03 Sep 2003
Posts: 6
Location: colorado springs CO USA

Thank you so much! I get paid penuts, so where should I mail your share? =D No, seriously thank you very much!!
_________________
Best Regards,
Mayel ><>
Back to top
View user's profile Send private message AIM Address
crazyleya
PostPosted: Wed May 03, 2006 3:18 pm    Post subject: Reply with quote

Newbie

Joined: 03 May 2006
Posts: 9

I tried the java trigger example and it works well when I have java -cp.... JavaTrigger on the applicid on the process. I am trying to call a shell script on the applicid and I get the following error "This must be a triggered application" Guess this is because I am not passing the MQTMC2 structure to the java program. Can somebody please help me pass the MQTMC2 structure?

Thanks much,
Ben
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed May 03, 2006 3:21 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The MQTMC2 is passed as a parameter on the triggered program - I believe it's the first or second.

So you just need to ensure that you pass that information through your shell script to the program you're calling.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed May 03, 2006 6:52 pm    Post subject: Reply with quote

Grand High Poobah

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

crazyleya wrote:
I tried the java trigger example and it works well when I have java -cp.... JavaTrigger on the applicid on the process. I am trying to call a shell script on the applicid and I get the following error "This must be a triggered application" Guess this is because I am not passing the MQTMC2 structure to the java program. Can somebody please help me pass the MQTMC2 structure?

Thanks much,
Ben


http://www.nynjmq.org/Triggering%20the%20right%20Java%20Environment.zip

Enjoy F.J.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
RogerLacroix
PostPosted: Wed May 03, 2006 8:43 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,

Just pass all of the command line parameters that the script received to your java program (standard shell scripting stuff). i.e.
Code:
nohup java MQTrigger "$@" &


Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
crazyleya
PostPosted: Thu May 04, 2006 2:54 pm    Post subject: Reply with quote

Newbie

Joined: 03 May 2006
Posts: 9

Thanks a lot guys. The ppt was very informative. I assigned "$@" to a variable and passed it to a function which had the java call. Works well.
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 » General Discussion » MQ Java Triggered server example
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.