0

I got an opportunity to work on IBM MQ testing recently. Since, i am new to this testing. i have referred multiple blogs in Stackoverflow to prepare our code. Currently i am referring following blog code to inject my XML payloads + Rfh2 header values(How to send message with RFH2 format?). Actually i am able to inject the request but i cannot see any response in listener.

I have tried adding below code snippet, but i am getting "com.ibm.mq.MQMessage@1d3ef24d" as output.

SampleResult.setResponseData(message.toString())
SampleResult.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT )
SampleResult.setLatency( stop.toEpochMilli() - start.toEpochMilli() )

We require message id, put time, put date details in the response. Could someone please help how to extract these values.

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, 'xxxxxxxxx')
mqProps.put(MQConstants.PORT_PROPERTY, 1414)
mqProps.put(MQConstants.HOST_NAME_PROPERTY, 'XXXXXXXXX')

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()
message.format = CMQC.MQFMT_RF_HEADER_2
def rfh2 = new MQRFH2()
rfh2.setEncoding(CMQC.MQENC_NATIVE)
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT)
rfh2.setFormat(CMQC.MQFMT_STRING)
rfh2.setNameValueCCSID(1208)
rfh2.setFieldValue('usr', 'Test', 'Country')

rfh2.write(message)

message.writeString('''${request_payload}''')

queue.put(message, pmo)
queue.close()
Devi R
  • 1
  • 2
  • Looks like you are trying to print the MQMessage object using System.out.println method. You will need to use messageId, putDateTime properties of MQMessage get the details. Please note messageId is a byte array. – Shashi May 24 '22 at 05:52
  • Thanks for your response @Shashi. Yeah i need to know how to print that messageId. – Devi R May 24 '22 at 08:40
  • MessageId is byte array. You will need to convert the every byte in the array to hexadecimal string before printing. Some sample here - https://stackoverflow.com/questions/15429257/how-to-convert-byte-array-to-hexstring-in-java – Shashi May 24 '22 at 08:44

1 Answers1

0

If you want to display generated message as the response data of the JSR223 Sampler you need to do something like:

SampleResult.setResponseData(message.readUTF(), 'UTF-8')

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for your response @Dmitri T. I am getting EOF file error when i use above code line.. – Devi R May 24 '22 at 08:39
  • You are using writeString method to write the payload when sending. For reading you will need to use readString method. – Shashi May 24 '22 at 08:42
  • Oh let me check with readString method. Thanks for your response @Shashi – Devi R May 24 '22 at 09:53