0

Question

I need to inject messages in IBM MQ with JMeter.

Format should be RFH2. I need to set Format field to empty and also change content of the header.

Which kind of JMeter object should I used to do that?

Can you help me please? Thanks a lot.

Update n°1

Thank to @DmitriT answer I'm able to send message in queue.

However, it seems that header content is not put in the header but before the message. Please find below an example:

Server logs with message sent with MQ Visual Edit

Header

 2020-04-21 11:07:59.913 DEBUG 48093 --- [DefaultMessageListenerContainer-2] 
 c.b.i.c.listeners.AbstractAgiListener    : Receive message on MQ with header : {someargs, 
 jms_destination=queue:///myqueue, someargs, Sender=mysender, someargs, jms_type=mcd://jms_byte,
 someargs}

Message

 <Document ...>...</Document>

Server logs with message sent with JMeter

Header

 2020-04-21 11:07:59.913 DEBUG 48093 --- [DefaultMessageListenerContainer-2] 
 c.b.i.c.listeners.AbstractAgiListener    : Receive message on MQ with header : {someargs}

Message

 RFH ¨ÿÿÿþ        ¸ <mcd><Msd>jms_bytes</Msd></mcd> 8<jms><Dst>queue:///myqueue</Dst>
<Pri>0</Pri></jms>    <usr><Sender>mysender</Sender></usr><Document ...>...</Document>

Any idea how to solve it please? Thank you.

Roger
  • 7,062
  • 13
  • 20
Royce
  • 1,557
  • 5
  • 19
  • 44

1 Answers1

1

The "JMeter object" you should use is JSR223 Sampler

  1. Download the relevant version of the com.ibm.mq.allclient library (with dependencies) and drop it to JMeter Classpath
  2. Restart JMeter to pick the libraries up
  3. Add JSR223 Sampler to your Test Plan
  4. Create the message according to your requirements and publish it to the queue. Reference code:

    import com.ibm.mq.MQAsyncStatus
    import com.ibm.mq.MQMessage
    import com.ibm.mq.MQPutMessageOptions
    import com.ibm.mq.MQQueueManager
    import com.ibm.mq.constants.CMQC
    import com.ibm.mq.constants.MQConstants
    import com.ibm.mq.headers.MQRFH2
    
    def mqProps = new Hashtable<String, Object>()
    mqProps.put(MQConstants.CHANNEL_PROPERTY, 'DEV.APP.SVRCONN')
    mqProps.put(MQConstants.PORT_PROPERTY, 1414)
    mqProps.put(MQConstants.HOST_NAME_PROPERTY, '192.168.99.100')
    
    def qManager = 'QM1'
    def queueName = 'DEV.QUEUE.1'
    
    
    def qMgr = new MQQueueManager(qManager, mqProps)
    def openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF
    def queue = qMgr.accessQueue(queueName, openOptions)
    
    def pmo = new MQPutMessageOptions()
    pmo.options = MQConstants.MQPMO_ASYNC_RESPONSE
    def message = new MQMessage()
    def rfh2 = new MQRFH2()
    rfh2.setEncoding(CMQC.MQENC_NATIVE)
    rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT)
    rfh2.setFormat(CMQC.MQFMT_STRING)
    rfh2.setNameValueCCSID(1208)
    rfh2.setFieldValue('your', 'data', 'here')
    rfh2.write(message)
    
    queue.put(message, pmo)
    queue.close()
    
    MQAsyncStatus asyncStatus = qMgr.getAsyncStatus()
    log.info('Successfully published: ' + asyncStatus.putSuccessCount + ' message(s)')
    

References:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you a lot for this answer! So, based on the code you provided, need I to create `producer` and `consumer`? Or just creating the message and posting it til get the response of the server is suffisant? – Royce Apr 20 '20 at 19:17
  • With this code I'm able to send the message in the queue. Thank you a lot. Just one last thing. It seems that the RFH2 content is put before the message and not in the header. I updated my question with details. Thank you again. – Royce Apr 21 '20 at 09:19