Put message that generate by iso8583 in custom jpos channel

102 views
Skip to first unread message

Mehrdad

unread,
Apr 3, 2024, 4:45:22 PMApr 3
to jPOS Users


Hi


Need to replace MYMESSAGE with isomsg of iso8583 sampler.



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.*;


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 {

        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);

            JMSTextMessage message = (JMSTextMessage) session.createTextMessage("MYMESSAGE");


 

            connection.start();

            sender.send(message);                                

                                                        

        } catch (JMSException e) {

            throw new ConfigurationException(e);

        }

    }          

}

Andrés Alcarraz

unread,
Apr 3, 2024, 5:05:01 PMApr 3
to jpos-...@googlegroups.com

That doesn’t seem to be the place to do that.

It is in the send method that you get the message to send to the queue.

There you just would use the packager to pack the message and send it to the queue, but it should be a binary message, not a text one. And it seems you are already doing that, according to another message you posted on the list:

    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);
        }
    }

So, why are you now trying to send a message in configuration time?

Andrés Alcarraz
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/7933225a-d6af-4674-b3fd-63362f4fc1b9n%40googlegroups.com.

Alejandro Revilla

unread,
Apr 3, 2024, 5:14:57 PMApr 3
to jpos-...@googlegroups.com

Doesn’t isoMsg.getBytes() throw an ISOException ("N/A in Composite"); ?

D
on’t you need a pack() ?



Andrés Alcarraz

unread,
Apr 3, 2024, 5:35:04 PMApr 3
to jpos-...@googlegroups.com

Good catch, TBH I didn’t inspect the code, just pasted what the OP posted.

As Alejandro says you need to use the packager to get the bytes, you can take a look at how BaseChannel does that:

            m.setDirection(ISOMsg.OUTGOING);
            ISOPackager p = getDynamicPackager(m);
            m.setPackager (p);
            m = applyOutgoingFilters (m, evt);
            evt.addMessage (m);
            m.setDirection(ISOMsg.OUTGOING); // filter may have dropped this info
            m.setPackager (p); // and could have dropped packager as well
            byte[] b = pack(m);

You can omit the filter part, I don’t think you need to implement filters for your use case.

Also, I don’t think extending BaseChannel is a good idea, since it is mainly for raw TCP/IP based connections.

Andrés Alcarraz

Mehrdad

unread,
Apr 4, 2024, 2:06:06 AMApr 4
to jPOS Users

Andrés Alcarraz, Would you please write complete code that you mean?
Thanks

Mark Salter

unread,
Apr 4, 2024, 3:30:43 AMApr 4
to jpos-...@googlegroups.com
On 04/04/2024 07:06, Mehrdad wrote:
Would you please write complete code that you mean?

Do you have no access to anyone that can understand and write basic java?

If helped for free here, your needs might be too great and could be never ending as getting an ISOMsg out through JMS is going to be the only the start - and you already have all the code to pull together.

If this really is a personal and non-commercial project then perhaps share that detail explicitly?


If you are working for a company or client, then may I suggest it is time to share with them that they need to employ some java skills.


-- 

Mark

signature.asc

Mehrdad

unread,
Apr 4, 2024, 3:44:54 AMApr 4
to jPOS Users

Mark Salter, thanks for your advised, but not help me.
I’ll try to enable debug code but can’t find any error or log that let me inspect issue deeply.


I try to send bytes, and didn’t return any error and run but mq didn’t receive message, and not show any error:

public void send(ISOMsg isoMsg) throws IOException, ISOException {
        try {
            // Create a BytesMessage
            BytesMessage jmsMsg = session.createBytesMessage();

            // Pack the ISO message and write its bytes to the JMS message
            jmsMsg.writeBytes(isoMsg.pack());

            // Send the JMS message

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


Also try to sent as text,  instead of BytesMessage, same result:

public void send(ISOMsg isoMsg) throws ISOException {
    try {
        // Create a TextMessage
        TextMessage jmsMsg = session.createTextMessage();

        // Set the text content of the JMS message
        jmsMsg.setText(new String(isoMsg.pack(), "ISO-8859-1")); // Assuming ISO-8859-1 encoding

        // Send the JMS message
        sender.send(jmsMsg);
    } catch (JMSException | UnsupportedEncodingException e) {

        throw new ISOException("Error sending JMS message", e);
    }
}

Any idea?
Thanks

Mark Salter

unread,
Apr 4, 2024, 2:18:29 PMApr 4
to jpos-...@googlegroups.com
There will be an error output somewhere.

Perhaps debug and step through?

Glad you are trying things.

You arenworkingnfor a company?  See if they have anyone that can help you?

-- 
Mark

-- 
Mark


-------- Original Message --------
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
signature.asc

Andrés Alcarraz

unread,
Apr 4, 2024, 5:00:50 PMApr 4
to jpos-...@googlegroups.com

Hi Mehrdad,

  1. I believe you already have all you need to write that code yourself, you can just take BaseChannel linked below as an example of how to write your channel
  2. I would have to write code that I can’t even test.

So the answer under these circumstances is no, but I, and the rest of the community here, can try to help you try to sort out any obstacle you find while you try to do it yourself. On the plus side, you’ll learn a lot in the process.

In another message, I mentioned that if you are using jPOS only for this, you may not want to learn all you would need. In that case, I would consider hiring someone that develops this for you, or try to find out another tool for the tests you want to perform.

Andrés Alcarraz

Mehrdad

unread,
Apr 5, 2024, 9:17:12 AMApr 5
to jPOS Users
Mark Salter, here is the log:  

IMG_9504.jpeg

Mark Salter

unread,
Apr 5, 2024, 9:24:26 AMApr 5
to jpos-...@googlegroups.com
For you to look at and debug rather than me.

I would address those "cannot be null" warnings, but you don't need an up target, so perhaps still caretaking too much BaseChannel.

Debug and step throughbyourbcodebas I suggested, that should give the most information on what is failing and why.

-- 
Mark


-------- Original Message --------
signature.asc

Mehrdad

unread,
Apr 5, 2024, 9:27:22 AMApr 5
to jPOS Users
Andrés Alcarraz, would you please tell me what is your idea about this issue or piece of code that complete code in my post, I’ll test it.
FYI: i put screenshot of output in my previous reply.

Any Idea?
Thanks

Andrés Alcarraz

unread,
Apr 5, 2024, 9:29:18 AMApr 5
to jPOS Users
I'm sorry but that is not an efficient or fun way to test and debug code

----
Enviado desde mi móvil, disculpas por la brevedad.

Sent from my cellphone, I apologize for the brevity.

Andrés Alcarraz.

Mehrdad

unread,
Apr 5, 2024, 10:10:16 AMApr 5
to jPOS Users
Alejandro Revilla, Here is the log.

I try to send bytes, and didn’t return any error and run but mq didn’t receive message, and not show any error:

public void send(ISOMsg isoMsg) throws IOException, ISOException {
        try {
            // Create a BytesMessage
            BytesMessage jmsMsg = session.createBytesMessage();

            // Pack the ISO message and write its bytes to the JMS message
            jmsMsg.writeBytes(isoMsg.pack());

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

IMG_9504.jpeg

Any idea?
Thanks

On Thursday, April 4, 2024 at 12:44:57 AM UTC+3:30 Alejandro Revilla wrote:

Mehrdad

unread,
Apr 5, 2024, 10:18:56 AMApr 5
to jPOS Users

Mark Salter, Here is that part of log that not show completely in screenshot, host name, and other parameters set correctly in channel adaptor, but Q2 not detect it!

2024-04-05 16:38:13,540 DEBUG n.c.b.j.i.ISO8583Config: Deploying <channel-adaptor name="jmeter-90b931b7-channel" logger="Q2"><in>jmeter-90b931b7-send</in><out>jmeter-90b931b7-receive</out><reconnect-delay>10000</reconnect-delay><wait-for-workers-on-stop>yes</wait-for-workers-on-stop><channel name="jmeter-90b931b7" 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="mychannel" /><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-05 16:38:13,588 DEBUG n.c.b.j.i.ISO8583Config: Deploying <qmux name="jmeter-90b931b7-mux" logger="Q2"><in>jmeter-90b931b7-receive</in><out>jmeter-90b931b7-send</out><unhandled>jmeter-90b931b7-unhandled</unhandled><ready>jmeter-90b931b7.ready</ready></qmux>

2024-04-05 16:38:13,589 WARN n.c.b.j.i.Q2: (org.jpos.q2.iso.ChannelAdaptor) channel-sender-jmeter-90b931b7-send

2024-04-05 16:38:13,589 WARN n.c.b.j.i.Q2: (org.jpos.q2.iso.ChannelAdaptor) hostname can't be null


Mark Salter

unread,
Apr 5, 2024, 11:01:25 AMApr 5
to jpos-...@googlegroups.com
Yeah, I am sure your setup is perfect and the code is somehow ignoring it.

Please take my guidance and debug your code for your problem.

We can't help you remotely and you have access tonall you need, if you would try.

I will now start ignoring you until you stop choosing to ignore me and my advise.

Have fun!

-- 
Mark

-- 
Mark


-------- Original Message --------
signature.asc

Andrés Alcarraz

unread,
Apr 5, 2024, 4:16:38 PMApr 5
to jpos-...@googlegroups.com

Hi Mehrdad, please don’t share logs as image. Share the text and in preformatted text please, same for the code, it makes it easier to read.

Also, one thing you should know, most of us are not experts on jmeter, just plain jPOS. Therefore, before you try to make your class work in jMeter, it would be a good advice to start a jPOS project from scratch. It makes it even harder for us to help you, trying to guess what jMeter could or not be doing.

So, you can go through the first and probably second jPOS tutorials to start a jPOS project and then modify the channel to use yours. It would be easier to debug that, and check if it connects to the queue, and the messages are being sent.

I’m sorry to tell you that if you want to go the jMeter/jPOS route you will need to understand jPOS and java deeper, that’s not optional. If that is not part of your job description, and you’re not willing to do it, then you should advise your employer that they need to hire someone else for that task. We can guide you, but we cannot do the things for you.

Best regards.

Andrés Alcarraz
Reply all
Reply to author
Forward
0 new messages