send iso8583 via jmeter using jmeter-iso8583 plugin to mq

90 views
Skip to first unread message

Mehrdad

unread,
Feb 19, 2024, 1:40:46 PMFeb 19
to jmeter-plugins
want to send iso8583 via jmeter using jmeter-iso8583 plugin to mq, create issue on github got this answer, what should i do next:
https://github.com/tilln/jmeter-iso8583/issues/73#issuecomment-1817217279

You have to write your own Channel Class that wraps the JMS objects.

It would have to implement ISOChannel to be able to connect, send, receive etc. via JMS queue.

It should implement Configurable so you can pass in required properties via the test plan, for example:

Below is an example of how you would access those properties.

You would also have to convert the ISOMsg that the ISO8583 Sampler generates into an appropriate JMS message, see below for an example.

public class JMSChannel implements ISOChannel, Configurable {
    MQQueueConnectionFactory cf;
    // etc., your other JMS objects

    public void setConfiguration(Configuration cfg) throws ConfigurationException {
        // From common "Channel Settings":
        cf.setHostName(cfg.get("host"));
        cf.setPort(cfg.getInt("port"));
        // From "Advanced Configuration":
        cf.setQueueManager(cfg.get("queueManager");
        cf.setChannel(cfg.get("channel"));
        // etc., your other config properties
    }

    public void send(ISOMsg isoMsg) throws IOException, ISOException {
        // Assuming your messages are send as bytes rather than text:
        BytesMessage jmsMsg = session.createBytesMessage();
        jmsMsg.writeBytes(isoMsg.getBytes());
        sender.send(jmsMsg);
    }
   // etc., other methods
}
Most other ISOChannels extend BaseChannel for sending messages via all sorts of network/TCP connections, so you may want to have a look at how that is done.

I hope this gives you some ideas and a starting point.

Any idea?

Dmitri T

unread,
Feb 20, 2024, 12:12:27 AMFeb 20
to jmeter-plugins
As the answer suggests "You have to write your own Channel Class" and then use its FQDN in the "Channel Class" section of the ISO8583 sampler.

I think there is easier way however, looking into the ISO8583 sampler source code you should be able to access an instance of ISOMsg as SampleResult.response or prev.respomse and then send it to MQ using a suitable JSR223 Test Element like it's described in IBM MQ Tutorial: Learn How to Testing With JMeter article.

Mehrdad

unread,
Mar 29, 2024, 10:02:40 AMMar 29
to jmeter-plugins
ok i’ll try to write below java code use base-channel as you mentioned, after compile this code it generates class file. What should i do next? Should i put class file in lib/ext directory of jmeter? Or it should be add into the iso8583.jar file to jmeter detect it?


Here is the code:

```

import org.jpos.iso.ISOChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.BaseChannel;
import org.jpos.core.Configuration;
import org.jpos.core.Configurable;
import org.jpos.core.ConfigurationException;

import javax.jms.*;
import com.ibm.mq.jms.*;

public class JMSChannel extends BaseChannel implements ISOChannel, Configurable {
    private MQQueueConnectionFactory cf;
    private MQQueueConnection connection;
    private MQQueueSession session;
    private MQQueueSender sender;


    public void setConfiguration(Configuration cfg) throws ConfigurationException {
        // Set JMS properties from configuration
        cf = new MQQueueConnectionFactory();
   try {

        cf.setHostName(cfg.get("host"));
        cf.setPort(cfg.getInt("port"));
        cf.setQueueManager(cfg.get("queueManager"));
        cf.setChannel(cfg.get("channel"));
        // Set other necessary properties (e.g., user ID, password)
   } catch (JMSException e) {


       throw new ConfigurationException("Error configuring JMS: " + e.getMessage());
    }
        // Create JMS objects
        try {
            connection = (MQQueueConnection) cf.createQueueConnection();
            session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            MQQueue queue = (MQQueue) session.createQueue("queue:///my.queue");
            sender = (MQQueueSender) session.createSender(queue);
        } catch (JMSException e) {
            throw new ConfigurationException("Error creating JMS objects", e);
        }
    }

    public void send(ISOMsg isoMsg) throws ISOException {
        try {
            // Convert ISO8583 message to JMS message

            BytesMessage jmsMsg = session.createBytesMessage();
            jmsMsg.writeBytes(isoMsg.getBytes());

            // Send JMS message to the queue
            sender.send(jmsMsg);
        } catch (JMSException e) {
            throw new ISOException("Error sending JMS message", e);
        }
    }

    // Implement other methods required by ISOChannel interface
    // (e.g., receive, connect, disconnect, etc.)
}

``` 
Reply all
Reply to author
Forward
0 new messages