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 API Support » Urgent! Set Correlation ID in response msg with AMI C++

Post new topic  Reply to topic
 Urgent! Set Correlation ID in response msg with AMI C++ « View previous topic :: View next topic » 
Author Message
syangloo
PostPosted: Sat May 07, 2005 8:56 pm    Post subject: Urgent! Set Correlation ID in response msg with AMI C++ Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Dear all

Currently i tryng the Server program which can read the request msg from queue and reply back with AMI programming in C++.

Now my broker is copy the request msg MsgID into CorrID column so that when it put to back end queue, the back end application (server) can copy the corrid into the response msg back for the front end application can match with the messageid where it waiting for.

My problem is i can't set the same corrid into the response msg with the request msg.

What wrong with it?
Any sample code for it?

Below is the sample of my code
Code:

AmBytes myMessageId = myReceiveMsg.getCorrelationId();
mySendMsg.setCorrelationId(AmBytes (myMessageId));


Thanks in advance...

Take care
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
fjb_saper
PostPosted: Sun May 08, 2005 5:38 am    Post subject: Re: Urgent! Set Correlation ID in response msg with AMI C++ Reply with quote

Grand High Poobah

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

syangloo wrote:
....
Below is the sample of my code
Code:

AmBytes myMessageId = myReceiveMsg.getCorrelationId();
mySendMsg.setCorrelationId(AmBytes (myMessageId));


Thanks in advance...

Take care

Shouldn't you be trying to do :
Code:

AmBytes myMessageId = myReceiveMsg.getMessageId();
mySendMsg.setCorrelationId(myMessageId);


And by the way isn't AMI out of support ??

Enjoy
Back to top
View user's profile Send private message Send e-mail
syangloo
PostPosted: Sun May 08, 2005 4:59 pm    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Dear fjb_saper

Thanks for you reply...

Code:

AmBytes myMessageId = myReceiveMsg.getMessageId();
mySendMsg.setCorrelationId(myMessageId);


You code is copy the request (receive) message MsgId into response (send) message CorrId, but now i need to copy the CorrId at the request message into response message CorrId. Because every time the MQ put the message into queue, the MsgId will be change. So that is we copy the MsgId into the CorrId, Front End application will not able to pick up the message. Because of the CorrId is not match with the MsgId it waiting for.

What you mean AMI out of support?
We dont have any AMI support services.

Regards
Syangloo
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
bower5932
PostPosted: Mon May 09, 2005 5:48 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

AMI is not out of support. However, there are no future plans to enhance it. Here is a quote from the actual SupportPac page:
Quote:
IMPORTANT NOTE
After June 2003, IBM has no plans to enhance the AMI with any new functions or platforms. IBM will however continue to support the AMI as described in the Technical Support sectioin below.

We would recommend that customers do not use the AMI for any new projects and do not extend usage in existing projects. This recommendation does not apply to functions shipped by other IBM products, such as DB2, that have made use of the AMI. IBM is working to ensure that these products are able to provide the same functionality as today without the AMI.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
fjb_saper
PostPosted: Mon May 09, 2005 12:16 pm    Post subject: Reply with quote

Grand High Poobah

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

syangloo wrote:
You code is copy the request (receive) message MsgId into response (send) message CorrId, but now i need to copy the CorrId at the request message into response message CorrId. Because every time the MQ put the message into queue, the MsgId will be change. So that is we copy the MsgId into the CorrId, Front End application will not able to pick up the message. Because of the CorrId is not match with the MsgId it waiting for.


Well in that case your code was right. However the big question: At what point in your flow does the msgid get set to the correlation id.
There is no point in transferring a non set correlationid to the msg.CorrelationId. !!

Enjoy
Back to top
View user's profile Send private message Send e-mail
syangloo
PostPosted: Mon May 09, 2005 9:33 pm    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Because we find out every time when the message put into a different queue, the msgid will be change. So that we need to copy the msgid into the corrid when the msg at message flow (broker) before it put the msg into host queue.

*corrid should not change when the msg put into different queue.

Then the hose adapter just need to copy the corrId from the request msg into the response msg corrid for the front end application able to pick up the message where it match the msgid with the corrid.

If my code is correct, why it not working? Did i need to convert the value before set it to the response msg?

Any setting at the AMI configuration file will effect the msgid or corrid?

Regards
syangloo
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
fjb_saper
PostPosted: Tue May 10, 2005 11:30 am    Post subject: Reply with quote

Grand High Poobah

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

syangloo wrote:
Because we find out every time when the message put into a different queue, the msgid will be change. So that we need to copy the msgid into the corrid when the msg at message flow (broker) before it put the msg into host queue.

*corrid should not change when the msg put into different queue.

Then the hose adapter just need to copy the corrId from the request msg into the response msg corrid for the front end application able to pick up the message where it match the msgid with the corrid.

If my code is correct, why it not working? Did i need to convert the value before set it to the response msg?

Any setting at the AMI configuration file will effect the msgid or corrid?

Regards
syangloo


Not quite. You really need to inspect your flow and find the first node where your message is being manipulated. (Probably the broker). This is where you need to set the correlation id using the message id. Now you can't do this in a blind manner. You probably will need to check if a correlation id has already been set. If yes carry forward. If no set the correlation id to the message id. This logic needs to be present at each of the nodes from there on.

Now when you get to the processing node the correlation id should already have been set. If it is not -- set it to the message id. Else pass it through.

Enjoy
Back to top
View user's profile Send private message Send e-mail
syangloo
PostPosted: Tue May 10, 2005 7:41 pm    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Yes.... Been check the CorrID in the host queue at the request msg level. Broker already successful copy the request msg msgid into corrid column.

That mean
Request msg MsgId = 123456 after client put the msg into broker queue.
Broker copy the MsgId 123456 into request msg CorrId with the same value (123456) b4 pass it to host queue.

Host receive the request msg with
MsgId = 654321 (new msgid)
CorrId=123456

In the MQ msg header it got Correlation ID and Correlation ID bytes, i prefer the Correlation Id Bytes to be send.... Did my code doing the correct way?
Any way i can display out the CorrId b4fore i copy n after set it to the response msg?

Regards
Syangloo
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
syangloo
PostPosted: Thu May 12, 2005 11:44 pm    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Dear All

Below is my program code....

Code:

static char * sccsid = (char*) "@(#) samples/mbi/Server.cpp, MBI, A120, A120-L010627.1 1.17.3.1 01/06/26 16:14:50";
// *******************************************************************
// *
// * Program name: Server
// *
// * Description: Sample AMI C++ program that receives requests and
// *              sends replies to these requests. This sample works
// *              with the AMI C++ sample Client.
// *
// * Statement:   Licensed Materials - Property of IBM
// *
// *               04L1773, 5765-B73
// *               04L1788, 5765-B74
// *               04L1816, 5765-B75
// *               04L1830, 5639-B43
// *               (C) Copyright IBM Corp. 1999, 2000
// ********************************************************************
// *  @START_COPYRIGHT@                                               *
// *                                                                  *
// *  Statement:     Licensed Materials - Property of IBM             *
// *                                                                  *
// *                 (C) Copyright IBM Corporation. 1999, 2001        *
// *                                                                  *
// *  @END_COPYRIGHT@                                                 *
// ********************************************************************
// *
// * Program Logic:
// *    Create an AmSessionFactory.
// *    From the AmSessionFactory, create an AmSession.
// *    From the AmSession, create an AmPolicy, an AmMessage for
// *       sending, an AmMessage for receiving, an AmSender and
// *       an AmReceiver.
// *    Open the AmSession and the AmReceiver. The AmSender is
// *       left unopened since it will be used as a response
// *       service for sending replies to requests arriving at
// *       the AmReceiver.
// *    [A] Wait for a request by issuing a receive() on
// *        the AmReceiver.
// *    [B] Read the data from the incoming AmMessage using the
// *        readBytes() method.
// *    [C] Use this data to build a reply and populate the outgoing
// *        AmMessage with this reply data.
// *    [D] Send the outgoing AmMessage by issuing send() on the
// *        AmSender remembering to pass the original request
// *        AmMessage on the call.
// *    [E] Reset both of the AmMessages.
// *    Perform [A]-[E] repeatedly until SAMPLE_MAX_REQUESTS has
// *        been reached.
// *    Close the AmReceiver and the AmSession.
// *    Delete all created objects.
// *
// *    Error handling follows a simple model, both errors and
// *    warnings are reported but warnings are generally
// *    ignored so that processing continues. In some cases, an
// *    error may be ignored, based on the reasonCode but
// *    generally they cause the program to cleanup and exit.
// *
// * compile using VC++
// * settings -
// * C/C++, add /I"c:\program files\IBM\MQSeries\amt\include"
// * Link, add amtCpp.lib or add the lib into the project (workspace)
// *******************************************************************
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>               
#include <ctype.h>
#include <time.h>
//#include <fstream.h>
//#include <memory.h>
}
# include <amtcpp.hpp>
#define SPACE 0x20                  
//#include <process.h>

void RemoveTab();
void remove_space(char *);
//-----------------------------------------------------------
// Put Delay Time to AMI
//-----------------------------------------------------------
void delay(double ticks)
{
       double sticks;
       sticks = clock();
       
       while( clock() < (sticks + ticks));
}

int main();
AMBOOL create(AmSessionFactory ** ppMySessionFactory,
         AmSession        ** ppMySession,
         AmPolicy         ** ppMyPolicy,
         AmSender         ** ppMyResponder,
         AmReceiver       ** ppMyReceiver,
         AmMessage        ** ppMySendMsg,
         AmMessage        ** ppMyReceiveMsg );

AMBOOL open(  AmSession&          mySession,
         AmReceiver&         myReceiver,
         AmPolicy&           myPolicy);

AMBOOL receiveSend(
         AmSender&           myResponder,
         AmReceiver&         myReceiver,
         AmMessage&          mySendMsg,
         AmMessage&          myReceiveMsg,
         AmPolicy&           myPolicy );

AMBOOL close( AmSession&          mySession,
         AmReceiver&         myReceiver,
         AmPolicy&           myPolicy);

AMBOOL destroy(
         AmSessionFactory ** ppMySessionFactory,
         AmSession        ** ppMySession,
         AmPolicy         ** ppMyPolicy,
         AmSender         ** ppMyResponder,
         AmReceiver       ** ppMyReceiver,
         AmMessage        ** ppMySendMsg,
         AmMessage        ** ppMyReceiveMsg );

AMBOOL handleErrors(AmErrorException& errorEx);
AMBOOL handleWarnings(AmWarningException& warningEx);

// ********************************************************************
// * The names used on the creation of the objects.
// *
// * SAMPLE_SESSION_NAME
// *    If you are not using the default queue manager, edit file
// *    amthost.xml to specify your queue manager name under the
// *    field 'defaultConnection'. Also open the session using the
// *    SAMPLE_POLICY_NAME.
// *
// * SAMPLE_POLICY_NAME
// *    This is the name used to create the AmPolicy used for all
// *    operations in this sample. The name matches a supplied Policy
// *    definition in the sample repository.
// *
// * SAMPLE_RECEIVER_NAME
// *    This is the name used to create the AmReceiver used for
// *    receiving the messages. The name matches a supplied Service
// *    definition in the sample repository.
// *
// * SAMPLE_RESPONDER_NAME
// *    This is the name used to create the AmSender used for
// *    responding to the requests. The name does not match a supplied
// *    Service definition in the sample repository as the details of
// *    the AmSender will be filled in by the AMI according to the
// *    nature of the request.
// *
// * SAMPLE_SEND_MESSAGE_NAME
// *    This is the name of the message being sent. The name is
// *    simply a user supplied tag for the message.
// *
// * SAMPLE_RECEIVE_MESSAGE_NAME
// *    This is the name of the message being received. The name is
// *    simply a user supplied tag for the message.
// *
// ********************************************************************
#define SAMPLE_SESSION_NAME          (char *)"AMT.SAMPLE.SESSION"
#define SAMPLE_POLICY_NAME           (char *)"PL.DEFAULT"
#define SAMPLE_RESPONDER_NAME        (char *)"SP.REPLIES"
#define SAMPLE_RECEIVER_NAME         (char *)"SP.REQUESTS"
#define SAMPLE_SEND_MESSAGE_NAME     (char *)"SP.REQUESTS.BROKERED"
#define SAMPLE_RECEIVE_MESSAGE_NAME  (char *)"AMT.SAMPLE.RECEIVE.MESSAGE"

// ********************************************************************
// * SAMPLE_MAX_STRING_LENGTH
// *    The data passed in messages in all the AMI samples are
// *    expressed as NULL terminated strings. This is the maximum
// *    string length allowed in the samples.
// *
// * SAMPLE_MAX_REQUESTS
// *    This is the number of requests that this program will service
// *    before exiting.
// *
// * SAMPLE_MSG_DATA
// *    This forms part of the request message data.
// *
// ********************************************************************
#define SAMPLE_MAX_STRING_LENGTH    (64*1024)
#define SAMPLE_MAX_REQUESTS         2
//#define SAMPLE_MSG_DATA             "Server REPLY to"

// *******************************************************************
// * main()
// *******************************************************************
int main()
{
   AmSessionFactory        * pMySessionFactory = NULL;
   AmSession               * pMySession        = NULL;
   AmSender                * pMyResponder      = NULL;
   AmReceiver              * pMyReceiver       = NULL;
   AmMessage               * pMySendMsg        = NULL;
   AmMessage               * pMyReceiveMsg     = NULL;
   AmPolicy                * pMyPolicy         = NULL;

   AMBOOL bSuccess = AMB_TRUE;

   printf(">>> START AMI Host Receive Send Server\n");

   bSuccess = create(&pMySessionFactory, &pMySession, &pMyPolicy,
            &pMyResponder, &pMyReceiver, &pMySendMsg,
            &pMyReceiveMsg);

   if (bSuccess == AMB_TRUE)
   {
      bSuccess = open(*pMySession, *pMyReceiver, *pMyPolicy);
   }
   if (bSuccess == AMB_TRUE)
   {
      bSuccess = receiveSend(*pMyResponder, *pMyReceiver, *pMySendMsg,
               *pMyReceiveMsg, *pMyPolicy);
   }
   if (close(*pMySession, *pMyReceiver, *pMyPolicy) == AMB_FALSE)
   {
      bSuccess = AMB_FALSE;
   }
   if (destroy( &pMySessionFactory, &pMySession, &pMyPolicy, &pMyResponder,
      &pMyReceiver, &pMySendMsg, &pMyReceiveMsg) == AMB_FALSE)
   {
      bSuccess = AMB_FALSE;
   }

   printf(">>> END AMI Host Receive Send\n");

   if (bSuccess == AMB_TRUE)
   {
      return EXIT_SUCCESS;
   }
   else
   {
      return EXIT_FAILURE;
   }
}

// *******************************************************************
// * Creates all of the objects needed by the sample.
// *******************************************************************
AMBOOL create(AmSessionFactory ** ppMySessionFactory,
         AmSession        ** ppMySession,
         AmPolicy         ** ppMyPolicy,
         AmSender         ** ppMyResponder,
         AmReceiver       ** ppMyReceiver,
         AmMessage        ** ppMySendMsg,
         AmMessage        ** ppMyReceiveMsg )
{
   AMBOOL bSuccess = AMB_TRUE;

   printf("   create()\n");
   try
   {
      // --------------------------------------------------------------
      // Since we are not specifying a name for the AmSessionFactory,
      // we expect the AMI data files to be stored in a well-known
      // location (see documentation).
      // --------------------------------------------------------------
      (*ppMySessionFactory) = new AmSessionFactory();

      (*ppMySession) = (*ppMySessionFactory)->createSession(SAMPLE_SESSION_NAME);

      (*ppMyPolicy) = (*ppMySession)->createPolicy(SAMPLE_POLICY_NAME);

      (*ppMyResponder) = (*ppMySession)->createSender(SAMPLE_RESPONDER_NAME);

      (*ppMyReceiver) = (*ppMySession)->createReceiver(SAMPLE_RECEIVER_NAME);

      (*ppMySendMsg) = (*ppMySession)->createMessage(SAMPLE_SEND_MESSAGE_NAME);
      (*ppMyReceiveMsg) = (*ppMySession)->createMessage(SAMPLE_RECEIVE_MESSAGE_NAME);

   }
   catch (AmErrorException &errorEx)
   {
      bSuccess = handleErrors(errorEx);
   }
   catch (AmWarningException &warningEx)
   {
      bSuccess = handleWarnings(warningEx);
   }
   return bSuccess;
}

// *******************************************************************
// * Opens all of the objects needed by the sample.
// *******************************************************************
AMBOOL open( AmSession&        mySession,
        AmReceiver&       myReceiver,
        AmPolicy&         myPolicy)
{
   AMBOOL bSuccess = AMB_TRUE;

   printf("   open() \n");
   try
   {
      // --------------------------------------------------------------
      // Open the AmSession and the AmReceiver but do not open the
      // AmSender. This is because the sender is in fact a responder
      // which will adapt according to the destination of the reply;
      // the open on this responder will happen implicitly using the
      // information passed to it in the original request AmMessage.
      // --------------------------------------------------------------
      mySession.open(myPolicy);
       printf("   mySession.open(myPolicy)\n");
      myReceiver.open(myPolicy);
       printf("   myReceiver.open(myPolicy)\n");
   }
   catch (AmErrorException &errorEx)
   {
      bSuccess = handleErrors(errorEx);
   }
   catch (AmWarningException &warningEx)
   {
      bSuccess = handleWarnings(warningEx);
   }
   return bSuccess;
}

// *******************************************************************
// * Receives the requests from the Client and replies on the
// * specified AmSender.
// *******************************************************************
AMBOOL receiveSend(
         AmSender&        myResponder,
         AmReceiver&      myReceiver,
         AmMessage&       mySendMsg,
         AmMessage&       myReceiveMsg,
         AmPolicy&        myPolicy)
{
   AMBOOL bSuccess = AMB_TRUE;
   
  char   reply[SAMPLE_MAX_STRING_LENGTH],/*buffer,*/*ptr,
         rquid1[36],rquid2[36],
        msgid[7],fn[SAMPLE_MAX_STRING_LENGTH],
        buf[SAMPLE_MAX_STRING_LENGTH], corrid[48];
   
   FILE *outFile;

   printf("   receiveSend()\n");
   // --------------------------------------------------------------
   // Loop until we have seen SAMPLE_MAX_REQUESTS and then exit
   // --------------------------------------------------------------
  for (;; delay(6000))
   {
      try
      {
    // -----------------------------------------------------------
    // Receive a request.
    // The AmSender, myResponder, is an unconfigured AmSender
    // which has not yet been opened. The AMI uses the replyTo
    // information in the incoming request to auto-configure the
    // AmSender, so that a reply to this request can be sent. This
    // type of AmSender is known as a responder.
    // The AmSender is used as a responder.
    // Since we may receive a warning which indicates we cannot
    // send a reply, AMRC_NO_REPLY_TO_INFO, we must activate the
    // AmWarningExceptions.
    // -----------------------------------------------------------
    myReceiver.enableWarnings(AMB_TRUE);
    myReceiver.receive(myReceiveMsg,/* myResponder,*/myPolicy);
    myReceiver.enableWarnings(AMB_FALSE);

    // -----------------------------------------------------------
    // Now the message is full of data, read it out
    // and display it.
    // -----------------------------------------------------------
    AmBytes pMyBytesIN = myReceiveMsg.readBytes(myReceiveMsg.getDataLength());
    //AmBytes myMessageId = myReceiveMsg.getCorrelationId();
    //mySendMsg.setCorrelationId(AmBytes (myMessageId));
    //AmBytes getCorrelationId();
    //printf("      <<< Correlation ID >> \n");
    //printf("        %s\n", myMessageId.dataPtr());
    printf("      <<< RECEIVED request message from Front End\n");
    printf("        %s\n", pMyBytesIN.dataPtr());
   
     //-------------------------------------------------------------
    // Manipulate original message in buffer to grap the MsgId,
    // RqUid1 and RqUid2
    //-------------------------------------------------------------

       /**************************************************************/
       /*                                                            */
       /*   Display name of resolved queue before first message      */
       /*                                                            */
       /**************************************************************/

       // get the rquid1
      //memset(ptr, 0, sizeof(ptr));
      ptr = strstr((char *)pMyBytesIN.dataPtr(),"RqUID>");
      memcpy(rquid1,ptr+6,36);
      rquid1[36]='\0';
      printf("   Rquid1: %s\n", rquid1);
      
      sprintf(fn,"echo %s > rquid1.txt", rquid1);
      system ( fn);

      // move the pointer and get the msgid
      ptr=ptr+46;
       ptr = strstr(ptr,"affin_ID>");
      memcpy(msgid,ptr+9,7);
      msgid[7]='\0';
      printf("   msgID1: %s\n", msgid);

      // move the pointer and get the rquid2
       ptr=ptr+71;
      ptr = strstr(ptr,"RqUID>");
      memcpy(rquid2,ptr+6,36);      
      rquid2[36]='\0';
      printf("   Rquid3: %s\n", rquid2);
      
      sprintf(fn,"echo %s > rquid2.txt", rquid2);
      system (fn);


      /** reply here **/
      //this code for windows
      sprintf(fn,"echo copy %s-response-1.xml+rquid1.txt+%s-response-2.xml+rquid2.txt+%s-response-3.xml %s-response.xml > copy1.bat",msgid,msgid,msgid,msgid);
      system(fn);

      // copy the completed receive msg to generic %-response.xml
      sprintf(fn,"copy1.bat");
      system(fn);
   
      // this code for unix (hp-ux)
      
      //sprintf(fn,"cat %s-response-1.xml > %s-response.xml;cat  rquid1.txt>> %s-response.xml;cat %s-response-2.xml >> %s-response.xml;cat rquid2.txt >> %s-response.xml;cat %s-response-3.xml >> %s-response.xml",
      //       msgid,msgid,msgid,msgid,msgid,msgid,msgid,msgid);
      //system (fn);

      // copy the completed reply msg to generic reply.xml
      //sprintf(fn,"cat %s-response.xml > reply.xml",msgid);
      //system(fn);
      
      //sprintf(fn,"copy1.bat");
      //system(fn);
      
      //sprintf(fn,"cat %s-response.xml reply.xml > copy2.bat",msgid);
      //system(fn);
      
      sprintf(fn,"echo copy %s-response.xml reply.xml > copy2.bat",msgid);
      system(fn);

      sprintf(fn,"copy2.bat");
      system(fn);

      RemoveTab();      // Call remove tab function

      if((outFile = fopen("reply.xml", "r")) == NULL)
          printf("Failed to open file for read \n");

      memset(buf, 0, sizeof(buf));
      while (!feof(outFile)) {
           fgets(reply,sizeof(reply),outFile);
             remove_space(reply);
           strcat((char *)buf,reply);
      }
      fflush(outFile);
      fclose(outFile);
       

    // -------------------------------------------------------------
    // Wrap the original message to show that the AMI Server
    // program saw it and send it back to the originator.
    // -------------------------------------------------------------
    AmBytes * pMyBytesOUT = new AmBytes((const char *)buf);
    mySendMsg.writeBytes(*pMyBytesOUT);
    //AmBytes myMessageId = myReceiveMsg.getCorrelationId();   
    //mySendMsg.setCorrelationId(myMessageId);  // Set Correlation ID 2 Msg ID
    //void setCorrelationId(AmBytes &correlId);
    AmBytes myMessageId = myReceiveMsg.getCorrelationId();
    mySendMsg.setCorrelationId(AmBytes (myMessageId));
    //AmBytes getCorrelationId();
    printf("      <<< Correlation ID >> \n");
    printf("        %s\n", myMessageId.dataPtr());
     // -------------------------------------------------------------
    // Send the reply.
    // (1) Since no AmPolicy is specified, the default policy
    //     is used.
    // (2) The original request message is passed in order to
    //     correlate the reply and allow the AmSender responder
    //     to locate where the reply is to be sent.
    // -------------------------------------------------------------
    myResponder.send(mySendMsg,myReceiveMsg, myPolicy);
    printf("      >>> SENT to Client\n");
    printf("        %s\n", buf);

    // -------------------------------------------------------------
    // Before next time round, reset the messages.
    // -------------------------------------------------------------
    mySendMsg.reset();
    myReceiveMsg.reset();
      }
      catch (AmErrorException &errorEx)
      {
    bSuccess = handleErrors(errorEx);
      }
      catch (AmWarningException &warningEx)
      {
    bSuccess = handleWarnings(warningEx);
      }
     
     printf("\n\n|||::: Waiting Next Message :::|||\n");
    
     if (bSuccess == AMB_FALSE)  //AMRC_NO_MSG_AVAILABLE
      {
         printf("   ReceiveSend Fail\n");
      }
  }
     return bSuccess;
}
 
// *******************************************************************
// * Closes all of the objects needed by the sample.
// *******************************************************************
AMBOOL close( AmSession&       mySession,
              AmReceiver&      myReceiver,
              AmPolicy&        myPolicy )
{
   AMBOOL bSuccess = AMB_TRUE;

   printf("   close()\n");
   try
   {
      // -------------------------------------------------------------
      // Close the AmReceiver and the AmSession, but not the AmSender.
      // The AmSender is a responder and is closed implicitly.
      // -------------------------------------------------------------
      myReceiver.close(myPolicy);
      mySession.close(myPolicy);
   }
   catch (AmErrorException &errorEx)
   {
      bSuccess = handleErrors(errorEx);
   }
   catch (AmWarningException &warningEx)
   {
      bSuccess = handleWarnings(warningEx);
   }
   return bSuccess;
}

// ******************************************************************
// * Deletes all of the objects used by the sample.
// ******************************************************************
AMBOOL destroy(AmSessionFactory ** ppMySessionFactory,
              AmSession         ** ppMySession,
              AmPolicy          ** ppMyPolicy,
              AmSender          ** ppMyResponder,
              AmReceiver        ** ppMyReceiver,
              AmMessage         ** ppMySendMsg,
              AmMessage         ** ppMyReceiveMsg )
{
   AMBOOL bSuccess = AMB_TRUE;

   printf("   destroy()\n");
   try
   {
      (*ppMySession)->deleteMessage(ppMySendMsg);
      (*ppMySession)->deleteMessage(ppMyReceiveMsg);
      (*ppMySession)->deleteReceiver(ppMyReceiver);
      (*ppMySession)->deleteSender(ppMyResponder);
      (*ppMySession)->deletePolicy(ppMyPolicy);
      (*ppMySessionFactory)->deleteSession(ppMySession);
      delete *ppMySessionFactory;
   }
   catch (AmErrorException &errorEx)
   {
      bSuccess = handleErrors(errorEx);
   }
   catch (AmWarningException &warningEx)
   {
      bSuccess = handleWarnings(warningEx);
   }
   return bSuccess;
}


// *******************************************************************
// * Generic error handling method.
// *
// * This simply displays error information.
// *
// * Returns AMB_TRUE if processing should continue, otherwise
// * AMB_FALSE.
// *
// * In a more realistic scenario a decision could be made here as to
// * whether the situation could be recovered from and appropriate
// * action taken. For example, if the open() on the AmSession failed
// * with a reasonCode2 from the transport layer indicating that the
// * underlying transport mechanism supporting the AmSession was
// * unavailable, an alternative AmSession might be selected.
// *
// *
// * The information to be reported concerning the error is extracted
// * from two places:
// * (1) The AmException
// * (2) The source of the AmException
// *******************************************************************
AMBOOL handleErrors(AmErrorException& errorEx)
{
   printf("<<< AmError >>>\n");
   printf("     from method[%s]\n", errorEx.getMethodName().text());
   printf("     of class[%s]\n", errorEx.getClassName().text());
   printf("     with reasonCode[%ld]\n", errorEx.getReasonCode());

   AmObject * source = errorEx.getSource();
   if (source != NULL)
   {
      AmStatus status = errorEx.getSource()->getLastErrorStatus();
      printf("     and reasonCode2[%ld]\n", status.getReasonCode2());

      source->clearErrorCodes();
   }
   return AMB_FALSE;
}

// *******************************************************************
// * Generic warning handling method.
// *
// * This simply displays warning information.
// *
// * If the server receives a message which has no ReplyTo
// * information, a reply cannot be sent and a warning
// * Exception will be generated. If this happens display
// * a message which indicates the situation explicitly.
// *
// * The information to be reported concerning the warning is
// * extracted from two places:
// * (1) The AmException
// * (2) The source of the AmException
// *******************************************************************
AMBOOL handleWarnings(AmWarningException& warningEx)
{
   if (warningEx.getReasonCode() == AMRC_NO_REPLY_TO_INFO)
   {
      printf("     AMRC_NO_REPLY_TO_INFO; ignoring request\n");
   }
   else
   {
      printf("<<< AmWarning >>>\n");
      printf("     from method[%s]\n", warningEx.getMethodName().text());
      printf("     of class[%s]\n", warningEx.getClassName().text());
      printf("     with reasonCode[%ld]\n", warningEx.getReasonCode());
   }

   AmObject * source = warningEx.getSource();
   if (source != NULL)
   {
      source->clearErrorCodes();
   }

   return AMB_TRUE;
}

//-----------------------------------------------------------
// Remove Tab from the reply message
//-----------------------------------------------------------
#define MAXSTR 1024
#define MAXTABSIZE 80
/*---------------------------------------------------------*/
static char *preadonly = "rt";
static char *pwriteonly = "wt";
static char *ptmpfile = "STRIPTAB.TMP";
static char si[MAXSTR+1] = {1};
static char so[MAXSTR+1] = {0};
static char nomefile[MAXSTR+1] = {0};
static char *perropen = "ERROR : Opening file (%s)";
static char *poverflow = "ERROR : Line too long (pos=%ld)";
/*---------------------------------------------------------*/
void RemoveTab()


    {
    int getfl = 1;
    int getsz = 1;
    int tabsize = 8;
    long pos = 0;
    FILE *fi;
    FILE *fo;
    int i,j,n,modified;
    //unsigned dt,tm;

        if (si[0]!=0)
        tabsize = atoi(si);

    if (tabsize<1) tabsize = 1;
    if (tabsize>MAXTABSIZE) tabsize = MAXTABSIZE;
    fi = fopen("reply.xml","rw");


        if (fi==NULL) {
        printf(perropen,"reply.xml");
        return;
    }
    // work only with 16 bit DOS compiler
    // only to preserve date/time file stamp
    //     s
    // _dos_getftime(fileno(fi),&dt,&tm);
    fo = fopen("STRIPTAB.TMP","wt");


        if (fo==NULL) {
        printf(perropen,"STRIPTAB.TMP");
        return;
    }


        while (fgets(si,MAXSTR,fi)!=NULL) {
        pos++;
        modified = n = 0;


            for (i = 0; i <= strlen(si); i++) {


                if (n>=MAXSTR) {
                printf(poverflow,pos);
                return;
            }


                if (si[i]=='\t') {
                modified = 1;


                    for (j = tabsize-(n % tabsize); j > 0; j--) {
                    so[n++] = so[n--];

                        if (n>=MAXSTR) {
                        printf(poverflow,pos);
                        return;
                    }
                }
            }
            else so[n++] = si[i];
        }
        fputs(so,fo);
        //if (modified) printf("%ld :[%s]",pos,so);
    }
    fclose(fi);
    fflush(fo);
    // see up
    //_dos_setftime(fileno(fo),dt,tm);
    fclose(fo);
    //unlink("reply.xml");
   remove("reply.xml");
   //CFile::Remove("reply.xml");
    rename("STRIPTAB.TMP","reply.xml");
}

//-----------------------------------------------------------
// Remove Space from the reply message
//-----------------------------------------------------------
void remove_space(char *buffi)
{
   while(*buffi!='\0')
   {
      if(*buffi=='\n')
         strcpy(buffi,buffi+1);
         
      else
         buffi++;
   }
}




Any idea where is the problem is?

Regards
Syangloo
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
syangloo
PostPosted: Mon May 16, 2005 12:03 pm    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

Any thing to do with the AMI setting???

Any one can help?

Take care
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
fjb_saper
PostPosted: Mon May 16, 2005 3:00 pm    Post subject: Reply with quote

Grand High Poobah

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

You have

corelid = msg.getCorrelationID()

respmsg.setCorrealtionID((byte[]) corelid)

I believe you need to check your output. In JMS and AMI was the precursor for JMS you have
String msg.getCorrelationID()
and byte[] msg.getCorrelationIDasBytes()


I believe if you had the right stuff you would probably get a wrong param exception or a class cast exception and so the correlid would never get set.

of course you should as well check out the message on the replyto queue to check if it has a corelation id just to make sure that my assumptions are correct. Use amqbcg.


Enjoy
Back to top
View user's profile Send private message Send e-mail
syangloo
PostPosted: Thu May 19, 2005 12:33 am    Post subject: Reply with quote

Centurion

Joined: 01 Oct 2002
Posts: 120
Location: Kuala Lumpur

As my testing.... i display out the messageid i get from the request message is like AMQ Qm.IVR.KL.00|!6aB^a

In MQ Explorer message properties indentifier we can get two MsgId n two CorrId and now look like i not getting the correct of corrId i want.

Now my problem is i can't the the corrId in 48bytes from the request message....

Who can show me the sample to get the 48bytes corrid and set it back to the response message?
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Urgent! Set Correlation ID in response msg with AMI C++
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.