How to send message with RFH2 format? - jmeter

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.

The "JMeter object" you should use is JSR223 Sampler
Download the relevant version of the com.ibm.mq.allclient library (with dependencies) and drop it to JMeter Classpath
Restart JMeter to pick the libraries up
Add JSR223 Sampler to your Test Plan
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

Related

How to print the response body using JSR223 sampler with MQ testing in JMeter

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()
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:
SampleResult.setResponseData()
MQMessage.readUTF()
IBM MQ testing with JMeter - Learn How

JMeter: how to send formatted text via SMPT sampler

Is there a way to send a formatted text with links via JMeter SMTP sampler?
Scenario:
I need to send an email, where one of the words e.g. My "Instagram" will have a link to my instagram page.
Option 1:
Create such email in Gmail, send it to myself, then download it as .eml file and send use "Send .eml" option in SMTP sampler.
However, my issue is that these links should be changed and lead to different instagram pages with each new email sent, thus I need to pass it as a variable from CSV file. This seems to be impossible to achieve with .eml file as it needs to be modified before each request. Unless there is a way?
Option 2 (preferred):
Somehow I need to format text in "Message body" of SMTP sampler. I've tried to copy/paste the same style and tags from "Original" .eml file, but it is always sent as a plain text and Gmail won't format it on client side.
Here is an example of RAW Gmail text with formatted link which I've tried to use in "Message" text box of SMTP Sampler:
Visit my account #dummyaccount<https://l.instagram.com/?u=https%3A%2F%2Ftaplink.> for more info.
Expecting to see the following in the email:
Visit my account #dummyaccount - where #dummyaccount is a hyperlink
Actual:
Visit my account #dummyaccounthttps://l.instagram.com/?u=https%3A%2F%2Ftaplink. for more info.
Any suggestion will be greatly appreciated.
I don't think you can customize the SMTP Sampler messages this way. You will need to either compose the message in an email application, save it to .eml file and send this .eml or if you want to build the message content dynamically you can use JSR223 Sampler and Groovy language for sending your message.
Example code:
Properties props = new Properties();
props.put("mail.smtp.host", "your-smtp-server-here");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
def session = javax.mail.Session.getInstance(props, new CredentialsAuthentication() as javax.mail.Authenticator)
def msg = new javax.mail.internet.MimeMessage(session)
def from = new javax.mail.internet.InternetAddress("your-email-address-here", "your first and last name");
msg.setFrom(from);
def toAddress = new javax.mail.internet.InternetAddress("your-recipient-here ");
msg.setRecipient(javax.mail.Message.RecipientType.TO, toAddress);
msg.setSubject("Test");
msg.setContent("<html>\n" +
"<body>\n" +
"\n" +
"<a href=\"http://link-to-your-instagram-profile\">\n" +
"Link to my Instagram</a>\n" +
"\n" +
"</body>\n" +
"</html>", "text/html")
javax.mail.Transport.send(msg);
class CredentialsAuthentication extends javax.mail.Authenticator {
#Override
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication("your-username#most-probably-with-email.com", "your-password-here")
}
}

RabbitMQ - SimpleAmqpClient - I am trying to send headers along with my message but the headers are not being sent; what am I doing wrong?

I am using the following: https://github.com/alanxz/SimpleAmqpClient
I am trying to send headers along with my message but the headers are not being sent; what am I doing wrong?
Here is how my code looks like. I have a configuration object with some basic configuration values.
auto channel = AmqpClient::Channel::Create("localhost", 5672, configuration.UserName, configuration.Password, configuration.VirtualHost, 131072);
channel->DeclareQueue(configuration.QueueName, false, true, false, true);
auto messageBody = "simple json string message nothing fancy"
auto message = AmqpClient::BasicMessage::Create(messageBody);
message->DeliveryMode(AmqpClient::BasicMessage::delivery_mode_t::dm_nonpersistent);
message->ContentType("application/json");
message->Type("XYZRequest");
message->AppId("a guid");
auto headerTable = message->HeaderTable();
headersTable.insert(std::pair<string, string>("Key-1", "value-1"));
headersTable.insert(std::pair<string, string>("Key-2", "value-2"));
channel->BasicPublish(std::string(), configuration.ScoreQueueName, message);
This sends the message to the queue and I can see all the details (AppID, Type, Message Body, etc.) on the RabbitMq management portal except the headers.
What am I missing? Is it some configuration or what is it?
I would appreciate if some one can give me a link to a basic tutorial on how to send headers.
I am stuck. Please help.
message->HeaderTable() does not return a reference to the headers, it returns a copy of it.
To set the headers you must construct the headersTable first, then use message->HeadersTable(headersTable).
Table headersTable;
headersTable.insert(std::pair<string, string>("Key-1", "value-1"));
headersTable.insert(std::pair<string, string>("Key-2", "value-2"));
message->HeadersTable(headersTable);

How to config a HTTP Request Method GET with JSON BODY in JMeter?

I'm facing the issue while writing the scenario in JMeter. It's API using GET Method and requires JSON BODY.
It's very easy if the method is POST/PUT. But I don't know how to do with method GET. I tried: Add HTTP Header Manager with Content-Type:application/json, but nothing help.
As I know, using BODY with GET request is the not the good way, but the developer team has implemented like that, and it can be worked with curl.
So I would like to know can we config this in JMeter or not? and How?
Thanks in advance.
In fact sending request body with HTTP GET request is not supported by Apache HttpComponents and hence in JMeter, you should be able to send a GET request with JSON body using JSR223 Sampler and the following code (assumes Groovy language):
import org.apache.http.HttpResponse
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils
public class HttpGetWithBody extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "GET";
#Override
public String getMethod() {
return METHOD_NAME;
}
}
def client = HttpClientBuilder.create().build();
def getRequest = new HttpGetWithBody();
getRequest.setURI(new URL("http://example.com").toURI());
def json = "{\"employees\":[\n" +
" {\"firstName\":\"John\", \"lastName\":\"Doe\"},\n" +
" {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\n" +
" {\"firstName\":\"Peter\", \"lastName\":\"Jones\"}\n" +
"]}";
def body = new StringEntity(json, "application/json", "UTF-8");
getRequest.addHeader("Content-Type", "application/json");
getRequest.setEntity(body);
def response = client.execute(getRequest);
def result = EntityUtils.toString(response.getEntity());
log.info(result);
See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for more information on using JSR223 test elements and groovy language and scripting best practices.
There is a reported bug in JMeter for this https://bz.apache.org/bugzilla/show_bug.cgi?id=60358 and looks like the fix is on the way. Hopefully this issue would be fixed soon.

How to list all the jms headers attributes in apache camel?

I'm trying to read the jms header in apache-camel route. The following is the route in which I'm reading body & header.
String endPointTopic = "activemq:topic:geoLoc";
String endPointTopicOut = endPointTopic + "_outbox";
from(endPointTopic)
.log("Message from Topic is ${body} & header is ${header.Action}")
.to(endPointTopicOut);
Basically the And from the logs I'm able to see the following, which means I'm able to read the body but not the id in header.
Message from Topic is GeoLocationInfoDTO{id=2, geoLocationUUId='null',
geoLocationName='null', geoLocationDesc='null',
geoLocationPolygon='null', geoLocationCenterLatitude='null',
geoLocationCenterLongitude='null'} & header is
And the following is the code in which I'm publishing the message to activeMQ through jms template.
private MessageHeaders getMessageHeaders(HttpMethod action) {
log.debug("DomainPublisher : getMessageHeaders");
Map <String, Object> headerMap = new HashMap<>();
headerMap.put("Action", action);
return new MessageHeaders(headerMap);
}
public void publish(BaseDTO dto, HttpMethod action) {
log.debug("DomainPublisher : type is : {} : ", dto.getClass().getName());
getJmsMessagingTemplate().convertAndSend(topicMap.get(dto.getClass().getName()), dto, getMessageHeaders(action));
}
Note: I also tried to log the header id like ${header.id} instead of ${header.Action} but nothing is getting printed.
And I also wanted to know all the headers that are available to the jms message.
You can log exchange with all headers and properties as shown in this example:
.to("log:like-to-see-all?level=INFO&showAll=true&multiline=true")
http://camel.apache.org/log.html
More information about JMS headers can be found here: http://camel.apache.org/jms.html
List of possible headers:
JMSCorrelationID - The JMS correlation ID.
JMSDeliveryMode - The JMS delivery mode.
JMSDestination - The JMS destination.
JMSExpiration - The JMS expiration.
JMSMessageID - The JMS unique message ID.
JMSPriority - The JMS priority (with 0 as the lowest priority and 9 as the highest).
JMSRedelivered - Is the JMS message redelivered.
JMSReplyTo - The JMS reply-to destination.
JMSTimestamp - The JMS timestamp.
JMSType - The JMS type.
JMSXGroupID - The JMS group ID.
As per the Claus Ibsen comment looks like JMS headers only allow certain types as headers and camel will drop invalid headers. And it looks like HttpMethod (type Enum) is been dropped by Camel. All I have to do in my code is convert the Enum as String while constructing the header.
headerMap.put("Action", action);
to
headerMap.put("Action", action.toString());
The JMS headers can be viewed from the karaf client console by running the following command:
activemq:browse --amqurl tcp://localhost:61616 --msgsel JMSMessaageID='1' -Vheader TEST.FOO
Note: The above are all example values, change according to your config.

Resources