Wednesday, 14 September 2016

MQ scripting vugen code for pushing message in Queue


            //Message Injection loop
            for(i=0;i<injectionRate;i++)
            {

                if (numberOfMsgsInjected==totalMessages)
                                break;
                try
                {
                text.delete(0,text.length());
                //appending the xml message.
                text.append(lr.eval_string("<Items MessageType=\"ADJUSTMENT\"><Item AdjustmentType=\"ADJUSTMENT\" Availability=\"TRACK\" ItemID=\"[ItemID]\" OrganizationCode=\"DEFAULT\" ProductClass=\"GOOD\" Quantity=\"10\" RemoveInventoryNodeControl=\"Y\" ShipNode=\"[BrandID]\" SupplyType=\"ONHAND\" UnitOfMeasure=\"EACH\"></Item></Items>"));

                //Convert to String 
                String str = text.toString();
                System.out.println(str);
       
                //Creating Message Queue
                MQMessage XMLMessage = new MQMessage();

                //Setting Message format
                XMLMessage.format = "MQSTR";
                //UTF encoding Supports
                XMLMessage.writeString(str)
               
                System.out.println("string" + XMLMessage);                  
                  // specify the message options...
            
                  MQPutMessageOptions pmo = new MQPutMessageOptions();    // same as MQPMO_DEFAULT
            
                 // put the message on the queue
            
                  qName.put(XMLMessage,pmo);
                  numberOfMsgsInjected = numberOfMsgsInjected + 1;
                   lr.start_transaction("MessageSend");
                  System.out.println("msg sent ...");
                  lr.end_transaction("MessageSend",lr.PASS);
                               
                }

                catch(Exception e)
                {
                System.out.println("error here");
                e.printStackTrace();
                System.exit(0);
                }

            }

            //Getting the time stamp in millisecond after message injection.
            timeInMillis2 = System.currentTimeMillis();
           
        //Calculating the message injection rate
        double timespend = (double)(timeInMillis2 - timeInMillis1);
        double injectionIntervalMillisec = multiplyingFactor * injectionInterval * 1000;
        try
        {

            if(injectionIntervalMillisec > timespend)
            {
           
            Thread.sleep((long)(injectionIntervalMillisec-timespend));
            
            }
        }
            catch (Exception e)
            {}

        if (numberOfMsgsInjected==totalMessages)
         {

            lr.exit(lr.EXIT_VUSER,lr.PASS);
         }

    return 0;
    }//end of action

 /**
 * LoadRunner method to terminate the established  connection
 * with middleware.
 */

    public int end() throws Exception
    {
        // Close the queue...
        qName.close();

        // Disconnect from the queue manager 
        qMgr.disconnect();
        return 0;
    }//end of end

}

No comments:

Post a Comment