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 IndexIBM MQ Installation/Configuration Supportget amqsput0.c to do files and not lines

Post new topicReply to topic
get amqsput0.c to do files and not lines View previous topic :: View next topic
Author Message
sbagdon
PostPosted: Tue Apr 28, 2015 8:55 am Post subject: get amqsput0.c to do files and not lines Reply with quote

Newbie

Joined: 28 Apr 2015
Posts: 1

We've gotten /opt/mqm/samp/bin/amqsputc to put to our queue, using env variables (MQCHLLIB, MQSSLKEYR and MQCHLTAB) and a channel-tab file.

We've compiled /opt/mqm/samp/amqsput0.c with non-threaded. Using the same setup, we are also able to put to the queue. So that works.

So sample or source, it works. The question:

Is there a patch file floating around out there, to convert the coding behavior of the source from... "put at every c/r", to "put at just the eot"? We want/need to put a multi-line file to the queue, and (don't ask) this would really be the only way to do it (modify the sample source)

Google says this has been asked before, and even after reading all the threads, still can't find the breadcrumbs to do this. we're not c programmers, and yes, we could absolutely, without doubt, figure it out... yet.. why not just ask first? : )

Anything out there like that?

Thanks!
Back to top
View user's profile Send private message
smdavies99
PostPosted: Tue Apr 28, 2015 9:19 am Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6077
Location: Somewhere over the Rainbow this side of Never-never land.

Perhaps something like this would do what you want?
Code:

/* putimg QueueName QMGRName HeaderFileName BlobFileName TrailerFileName */



 /********************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
#include <errno.h>
    /* includes for MQI */
 #include <cmqc.h>

 int main(int argc, char **argv)
 {
   /*  Declare file and character for sample input                   */
   FILE *fp_blob;
   /*   Declare MQI structures needed                                */
   MQOD     od = {MQOD_DEFAULT};    /* Object Descriptor             */
   MQMD     md = {MQMD_DEFAULT};    /* Message Descriptor            */
   MQPMO   pmo = {MQPMO_DEFAULT};   /* put message options           */
      /** note, sample uses defaults where it can **/

   MQHCONN  Hcon;                   /* connection handle             */
   MQHOBJ   Hobj;                   /* object handle                 */
   MQLONG   O_options;              /* MQOPEN options                */
   MQLONG   C_options;              /* MQCLOSE options               */
   MQLONG   CompCode;               /* completion code               */
   MQLONG   OpenCode;               /* MQOPEN completion code        */
   MQLONG   Reason;                 /* reason code                   */
   MQLONG   CReason;                /* reason code for MQCONN        */
   MQLONG   messlen;                /* message length                */
   long       blen,hlen = 0;
   size_t   flen;
   char     *msg_buffer;    /* message buffer                */
   char     QMName[50];             /* queue manager name            */
   char     *tbuffer;
   char     *hbuffer;
   char     *bbuffer;

//   printf("Sample AMQSPUT0 start\n");
   if (argc < 4)
   {
     printf("Required parameter(s) missing\n");
    printf(" Usage \n    putimg QName QMGRName File\n\n");
     exit(99);
   }
 
    msg_buffer = (char *) malloc(10240000);
    hbuffer = (char *) malloc(102400);
    bbuffer = (char *) malloc(10240000);
    tbuffer = (char *) malloc(102400);
   /******************************************************************/
   /*                                                                */
   /*   Connect to queue manager                                     */
   /*                                                                */
   /******************************************************************/
   QMName[0] = 0;    /* default */
   strcpy(QMName, argv[2]);
   MQCONN(QMName,                  /* queue manager                  */
          &Hcon,                   /* connection handle              */
          &CompCode,               /* completion code                */
          &CReason);               /* reason code                    */

   /* report reason and stop if it failed     */
   if (CompCode == MQCC_FAILED)
   {
     printf("MQCONN ended with reason code %d\n", CReason);
     exit( (int)CReason );
   }

   /******************************************************************/
   /*                                                                */
   /*   Use parameter as the name of the target queue                */
   /*                                                                */
   /******************************************************************/
   strncpy(od.ObjectName, argv[1], (size_t)MQ_Q_NAME_LENGTH);
   if ((fp_blob = fopen(argv[3], "r")) == NULL)
   {
      printf("\n - ERROR opening file [%s]\n", argv[3]);
      exit(99);
   }

   /******************************************************************/
   /*                                                                */
   /*   Open the target message queue for output                     */
   /*                                                                */
   /******************************************************************/

     O_options = MQOO_OUTPUT            /* open queue for output     */
               | MQOO_FAIL_IF_QUIESCING /* but not if MQM stopping   */
               ;                        /* = 0x2010 = 8208 decimal   */


   MQOPEN(Hcon,                      /* connection handle            */
          &od,                       /* object descriptor for queue  */
          O_options,                 /* open options                 */
          &Hobj,                     /* object handle                */
          &OpenCode,                 /* MQOPEN completion code       */
          &Reason);                  /* reason code                  */

   /* report reason, if any; stop if failed      */
   if (Reason != MQRC_NONE)
   {
     printf("MQOPEN ended with reason code %d\n", Reason);
   }

   if (OpenCode == MQCC_FAILED)
   {
     printf("unable to open queue for output\n");
   }

   /******************************************************************/
   /*                                                                */
   /*   Read lines from the file and put them to the message queue   */
   /*   Loop until null line or end of file, or there is a failure   */
   /*                                                                */
   /******************************************************************/
   CompCode = OpenCode;        /* use MQOPEN result for initial test */
   //fp = stdin;

   memcpy(md.Format,           /* character string format            */
          MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH);

   /******************************************************************/
   /* Use these options when connecting to Queue Managers that also  */
   /* support them, see the Application Programming Reference for    */
   /* details.                                                       */
   /* These options cause the MsgId and CorrelId to be replaced, so  */
   /* that there is no need to reset them before each MQPUT          */
   /******************************************************************/
   /* pmo.Options |= MQPMO_NEW_MSG_ID;                               */
   /* pmo.Options |= MQPMO_NEW_CORREL_ID;                            */

   //while (CompCode != MQCC_FAILED)
   //{
     memset(msg_buffer , NULL , sizeof(msg_buffer));
     memset(bbuffer, NULL , sizeof(hbuffer));

    flen = fread(bbuffer, 1, 1024000  , fp_blob);
    if ( flen == 0)
    {
      printf("\n - Error on Binary read Errno = [%d][%s]\n", errno,(strerror(errno)));
    }

    blen = strlen(bbuffer);
    memmove((msg_buffer), bbuffer, blen);
    messlen =  blen ;
//printf("p4 %d\n", messlen);
     /****************************************************************/
     /*                                                              */
     /*   Put each buffer to the message queue                       */
     /*                                                              */
     /****************************************************************/
     if (messlen > 0)
     {
       /**************************************************************/
       /* The following two statements are not required if the       */
       /* MQPMO_NEW_MSG_ID and MQPMO_NEW _CORREL_ID options are used */
       /**************************************************************/
       memcpy(md.MsgId,           /* reset MsgId to get a new one    */
              MQMI_NONE, sizeof(md.MsgId) );

       memcpy(md.CorrelId,        /* reset CorrelId to get a new one */
              MQCI_NONE, sizeof(md.CorrelId) );

       MQPUT(Hcon,                /* connection handle               */
             Hobj,                /* object handle                   */
             &md,                 /* message descriptor              */
             &pmo,                /* default options (datagram)      */
             messlen,             /* message length                  */
             msg_buffer,          /* message buffer                  */
             &CompCode,           /* completion code                 */
             &Reason);            /* reason code                     */

       /* report reason, if any */
       if (Reason != MQRC_NONE)
       {
         printf("MQPUT ended with reason code %d\n", Reason);
       }
     }
     else   /* satisfy end condition when empty line is read */
       CompCode = MQCC_FAILED;
   //}

   /******************************************************************/
   /*                                                                */
   /*   Close the target queue (if it was opened)                    */
   /*                                                                */
   /******************************************************************/
   if (OpenCode != MQCC_FAILED)
   {

       C_options = MQCO_NONE;        /* no close options             */


     MQCLOSE(Hcon,                   /* connection handle            */
             &Hobj,                  /* object handle                */
             C_options,
             &CompCode,              /* completion code              */
             &Reason);               /* reason code                  */

     /* report reason, if any     */
     if (Reason != MQRC_NONE)
     {
       printf("MQCLOSE ended with reason code %d\n", Reason);
     }
   }

   /******************************************************************/
   /*                                                                */
   /*   Disconnect from MQM if not already connected                 */
   /*                                                                */
   /******************************************************************/
   if (CReason != MQRC_ALREADY_CONNECTED)
   {
     MQDISC(&Hcon,                   /* connection handle            */
            &CompCode,               /* completion code              */
            &Reason);                /* reason code                  */

     /* report reason, if any     */
     if (Reason != MQRC_NONE)
     {
       printf("MQDISC ended with reason code %d\n", Reason);
     }
   }

   /******************************************************************/
   /*                                                                */
   /* END OF AMQSPUT0                                                */
   /*                                                                */
   /******************************************************************/
//   printf("Sample AMQSPUT0 end\n");
   return(0);
 }



This was developed for MQ 6.0.2.x around 8 years ago so there is no guarantee that it will work now.
Thus there is no warranty or support. Please take this hack to amqsputc and do what you want with it.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Mon May 04, 2015 2:27 pm Post subject: Re: get amqsput0.c to do files and not lines Reply with quote

Jedi Knight

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

sbagdon wrote:
Google says this has been asked before, and even after reading all the threads, still can't find the breadcrumbs to do this.

One of those links would have taken you to http://www.capitalware.com/mq_code_c.html

On that page, you will find a program called: File2Msg (and its twin, Msg2File). File2Msg does exactly what you are looking for.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
ankur
PostPosted: Sun Apr 15, 2018 11:39 pm Post subject: Re: get amqsput0.c to do files and not lines Reply with quote

Newbie

Joined: 15 Apr 2018
Posts: 3

RogerLacroix wrote:
sbagdon wrote:
Google says this has been asked before, and even after reading all the threads, still can't find the breadcrumbs to do this.

One of those links would have taken you to http://www.capitalware.com/mq_code_c.html

On that page, you will find a program called: File2Msg (and its twin, Msg2File). File2Msg does exactly what you are looking for.

Regards,
Roger Lacroix
Capitalware Inc.



Hi Roger,

I have downloaded the program from above site. I am just wondering how to use it. Can you let me know if you have instruction manual on its usage, install etc. If there is a trial version available then we shall be interested in trying that before purchase (if its not a freeware). I am new to MQ and trying to figure out how to send contents of our xml file as a message without it being broken down in multiple messages for each line.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Mon Apr 16, 2018 9:48 am Post subject: Reply with quote

Jedi Knight

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

Open File2Msg.c with a text editor (i.e. notepad) and there is a description at the top. Also, starting at line # 77 is the usage information. Or you can run it without any parameters and it will display the usage parameters. It is the world's most basic program: read a file and put the contents on a queue as a message.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
ankur
PostPosted: Mon Apr 16, 2018 7:59 pm Post subject: Reply with quote

Newbie

Joined: 15 Apr 2018
Posts: 3

RogerLacroix wrote:
Open File2Msg.c with a text editor (i.e. notepad) and there is a description at the top. Also, starting at line # 77 is the usage information. Or you can run it without any parameters and it will display the usage parameters. It is the world's most basic program: read a file and put the contents on a queue as a message.

Regards,
Roger Lacroix
Capitalware Inc.


Thanks a lot Roger, I am novice in C as well as MQ. Can you let me know if:
1). I need to compile file2msg.c first?
2). Where should this file be run from? We have mq installed on UNIX (Solaris) under /opt/mq.
3). I don't have access to above directory ..I am getting this error while compiling "cannot find include file: <cmqc.h>" while file2msg.c is being compiled from a different directory. Do I need to copy file2msg.c to some other directory and compile from there?

Kindly suggest.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Apr 17, 2018 8:48 am Post subject: Reply with quote

Jedi Knight

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

Those MQ samples are for developers who are familiar with MQ. Do you have the MQ SDK installed? Ask your MQAdmin. cmqc.h is part of the MQ SDK and on Solaris, it is in /opt/mqm/inc/

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Installation/Configuration Supportget amqsput0.c to do files and not lines
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.