How to send message with RFH2 format?

前提是你 提交于 2020-04-30 06:32:47

问题


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.


回答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:

  • MQRFH2 class
  • Handling IBM MQ message headers with IBM MQ classes for Java
  • IBM MQ testing with JMeter - Learn How


来源:https://stackoverflow.com/questions/61321214/how-to-send-message-with-rfh2-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!