tilln / jmeter-iso8583

ISO8583 Plugin for JMeter
MIT License
62 stars 32 forks source link

variables not pass to jpose-q2 for custom channel #86

Closed mehrdad2000 closed 2 months ago

mehrdad2000 commented 3 months ago

Hi I try to set some variables in "ISO8583 Connection Configuration" for custom channel but seems it doesn't pass variables to jpos!

in first line of log it show get host and other variables for channel-adaptor successfully, but in second line when start jpos-q2 seems doesn't pass variables to it! and return "hostname can't be null"

here is the log:

2024-04-06 11:45:13,491 DEBUG n.c.b.j.i.ISO8583Config: Deploying <channel-adaptor name="jmeter-cedaeb2d-channel" logger="Q2"><in>jmeter-cedaeb2d-send</in><out>jmeter-cedaeb2d-receive</out><reconnect-delay>10000</reconnect-delay><wait-for-workers-on-stop>yes</wait-for-workers-on-stop><channel name="jmeter-cedaeb2d" class="org.jpos.iso.channel.JMSChannel" packager="org.jpos.iso.packager.GenericPackager" header="0000" logger="Q2"><property name="packager-config" value="/opt/apache-jmeter-5.6.2/configs/packager/iso2003ascii_NEW.xml" /><property name="host" value="192.168.1.10" /><property name="port" value="9000" /><property name="channel" value="APP.SVRCONN" /><property name="queueManager" value="myqmanager" /><property name="user" value="myuser" /><property name="pass" value="mypass" /><property name="qname" value="queue:///APP.foo.bar" /></channel></channel-adaptor>

2024-04-06 11:45:13,767 WARN n.c.b.j.i.Q2: (org.jpos.q2.iso.ChannelAdaptor) channel-sender-jmeter-cedaeb2d-send

2024-04-06 11:45:13,767 WARN n.c.b.j.i.Q2: (org.jpos.q2.iso.ChannelAdaptor) hostname can't be null

Any idea? Thanks

tilln commented 3 months ago

@mehrdad2000 Sorry, but you have to provide more information than this. I can only guess that

But those are only guesses.

In any case, the issue is unlikely to be caused by this plugin or the jPOS framework, but quite possibly your own implementation, unless you have thoroughly tested it, for which you have provided no indication, and rather outside JMeter as the jPOS community recommends as well).

Until you have done your due diligence, please stop spamming more issues, but use discussions or the jPOS-users group instead.

mehrdad2000 commented 3 months ago

@tilln Thank you so much for your hints, after several workaround finally figure out what happen here. :)) call function setConfiguration as you mention missed. also, after send request I should implement disconnect method. Here is the final JMSChannel that work with jmeter-iso8583 plugin.

package org.jpos.iso.channel;

import com.ibm.jms.JMSTextMessage;
import com.ibm.mq.jms.*;
import com.ibm.msg.client.wmq.WMQConstants;
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 java.io.*;
public class JMSChannel extends BaseChannel implements ISOChannel, Configurable {
    private MQQueueConnectionFactory cf;
    private MQQueueConnection connection;
    private MQQueueSession session;
    private MQQueueSender sender;

    @Override
    public void setConfiguration(Configuration cfg) throws ConfigurationException {
        super.setConfiguration(cfg); // Call BaseChannel's setConfiguration
        try {
            cf = new MQQueueConnectionFactory();
            cf.setHostName(cfg.get("host"));
            cf.setPort(cfg.getInt("port"));
            cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
            cf.setQueueManager(cfg.get("queueManager"));
            cf.setChannel(cfg.get("channel"));
            cf.setStringProperty(WMQConstants.USERID, cfg.get("user"));
            cf.setStringProperty(WMQConstants.PASSWORD, cfg.get("pass"));

            connection = (MQQueueConnection) cf.createQueueConnection();
            session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            MQQueue queue = (MQQueue) session.createQueue(cfg.get("qname"));
            sender = (MQQueueSender) session.createSender(queue);

            connection.start();

        } catch (JMSException e) {
            throw new ConfigurationException(e);
        }
    }

    @Override
    public void disconnect() throws IOException {
        try {
            if (sender != null) {
                sender.close();
            }
            if (session != null) {
                session.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (JMSException e) {
            throw new IOException(e);
        }
    }

@Override
public void send(ISOMsg isoMsg) throws IOException, ISOException {
    try {
        // Set header (replace "0000" with your desired header value)
        Configuration cfg = getConfiguration();
        String headerValue = cfg.get("header");
        isoMsg.setHeader(headerValue.getBytes());

        //isoMsg.setHeader(cfg.get(headerValue)).getBytes()); // Replace "0000" with channelHeader

        // Convert the header to a string
        String headerStr = new String(isoMsg.getHeader());

        TextMessage jmsMsg = session.createTextMessage();
        // Append the header to the beginning of the message text
        jmsMsg.setText(headerStr + new String(isoMsg.pack()));

        sender.send(jmsMsg);
    } catch (JMSException e) {
        throw new IOException(e);
    }
}