ISOMsg parallel request to multiple MUX

294 views
Skip to first unread message

Chikodi Nwanjoku

unread,
Jan 23, 2018, 11:53:13 AM1/23/18
to jPOS Users
i have a situation where i have to send an ISOMsg request to two channels in parallel get the result from both channels and compare some fields from both results before responding to the client that sent the request, please how do i go about this. below is what i have done


@Override
  public boolean process ( ISOSource isoSrc, ISOMsg isoMsg ) { 

      try{
        if(isoMsg.getMTI() .equals("0200")){

            MUX mux = (MUX) NameRegistrar.getIfExists("mux.jpos-host1-mux");

            ISOMsg reply = mux.request(isoMsg, 10 * 1000);

            if(reply != null){
                System.out.println(new String(reply.pack()));

                if(reply.getValue(39).equals("00")){
                    MUX mux_bank = (MUX) NameRegistrar.getIfExists("mux.jpos-host2-mux");
                    ISOMsg reply_bank = mux_bank.request(isoMsg, 10 * 1000);
                    if (isoMsg.hasField(39)) {
                            if(reply_bank.getValue(39).equals("00")){
                                reply.set(39, "00");
                                isoSrc.send(reply_bank);

                            }
                      }else{
                        //send a reversal to host1
                    }
                }else{
                    isoSrc.send(reply);
                }
            }
        }

      }catch(ISOException e){

      } catch (IOException ex) {
          Logger.getLogger(ISO_HAWK.class.getName()).log(Level.SEVERE, null, ex);
      }
      return false;
  }

is this a correct way to go about this (i.e considering the response time will be bigger, because i have to get a response from host1 before sending the request to host2 etc). or is there a better way to achieve this? and please how do i go about it?

Andrés Alcarraz

unread,
Jan 23, 2018, 12:15:30 PM1/23/18
to jPOS Users
Well since you need to Know the answer from the first host before knowing if you need to send to the second one you cannot parallelize the requests.

Therefore using just a request listener that sounds good enough.

However the standard jpos way of doing these things is using a transaction manager. Which can be somehow more overwhelming at first but provides a more consistent development of components and following of the transaction flow.

You can see it's usage in the tutorials at www.jpos.org/tutorials.

There you will see that there are already components (participants) that do some of the work for you like querying the bank hosts.

My 2 cents

Andrés Alcarraz

Enviado desde mi móvil


--
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/9abcf50a-545a-4e8d-8782-c949d80a05a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chikodi Nwanjoku

unread,
Jan 23, 2018, 12:46:40 PM1/23/18
to jPOS Users
Thank you Andres for your response..i already did that, but dont know how to implement the scenario below is my transaction manager

12_transaction_manager.xml

<txnmgr name="txnmgr" logger="Q2" class="org.jpos.transaction.TransactionManager">
    <property name="space" value="tspace:mySpace"/>
    <property name="queue" value="TransactionQueue"/>
    <property name="max-sessions" value="10"/>

    <participant class="main.java.com.transaction.manager.Switch" logger="Q2">
      <property name="0800" value="NetworkManagement" />
      <property name="0200" value="FinancialTransaction" />
    </participant>

    <participant class="main.java.com.transaction.manager.FinancialTransactionResponse" logger="Q2"/>

    <group name="NetworkManagement">
      <participant class="main.java.com.transaction.manager.NetworkManagementResponse" logger="Q2" />
    </group>

    <group name="FinancialTransaction">
      <participant class="main.java.com.transaction.manager.FinancialTransactionValidateMessage" logger="Q2" />
      <participant class="main.java.com.transaction.manager.FinancialTransactionQueryRemoteHost1" logger="Q2" />


<participant class="main.java.com.transaction.manager.FinancialTransactionQueryRemoteHost2" logger="Q2" />

    </group>

</txnmgr>



in my FinancialTransactionQueryRemoteHost1 i have

@Override
    public int prepare(long l, Serializable srlzbl) {
        try{

            channelManager =  ((ChannelManager) NameRegistrar.get("jpos-host1-adaptor"));
            ISOMsg reqMsg = (ISOMsg) ((Context) srlzbl).get(Constants.REQUEST_KEY);
            ISOMsg respMsg = channelManager.sendMsg(reqMsg);
            ((Context) srlzbl).put(Constants.RESPONSE_KEY, respMsg);
            return PREPARED;

        }catch(NameRegistrar.NotFoundException e){
            e.printStackTrace();
            return ABORTED;
        }catch(Throwable t){
            t.printStackTrace();
            return ABORTED;
        }

    }
in my FinancialTransactionQueryRemoteHost2 i have

    @Override
        public int prepare(long l, Serializable srlzbl) {
            try{

                channelManager =  ((ChannelManager) NameRegistrar.get("jpos-host2-adaptor"));
                ISOMsg reqMsg = (ISOMsg) ((Context) srlzbl).get(Constants.REQUEST_KEY);
                ISOMsg respMsg = channelManager.sendMsg(reqMsg);
                ((Context) srlzbl).put(Constants.RESPONSE_KEY, respMsg);
                return PREPARED;

            }catch(NameRegistrar.NotFoundException e){
                e.printStackTrace();
                return ABORTED;
            }catch(Throwable t){
                t.printStackTrace();
                return ABORTED;
            }

        }
in my Financialtransactionresponse i have

@Override
  public int prepare(long id, Serializable context) {
    Context ctx = (Context)context;
        ISOMsg respMsg = (ISOMsg)ctx.get(Constants.RESPONSE_KEY);
 //Get IsoMsg from host1
 //Get IsoMsg from host2
 //compare field 39 response if both are 00 
        
        ctx.put(Constants.RESPONSE_KEY,respMsg);
        return PREPARED;
  }
in my transactionresponse how do i get the response of the 2 participant so i can compare before responding i.e comment above on how i would like it to be achieved
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Chikodi Nwanjoku

unread,
Jan 23, 2018, 12:51:27 PM1/23/18
to jPOS Users
also its not necessary i know the response from host 1 before proceeding to host2 , but i just need to make sure i check the response of the 2 hosts before proceeding.


On Tuesday, January 23, 2018 at 6:15:30 PM UTC+1, Andrés Alcarraz wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Andrés Alcarraz

unread,
Jan 23, 2018, 12:58:05 PM1/23/18
to jpos-...@googlegroups.com

Hi, I was just answering your question in StackOverflow then. I just finished. Bur according to your code you don't send to the second host if the first reply is null or rejected.

I remember reading something to paralelize participants, but I'm not sure and don't remember how.

Best regards.

Andrés



El 23/01/18 a las 14:51, Chikodi Nwanjoku escribió:

Chikodi Nwanjoku

unread,
Jan 23, 2018, 1:14:28 PM1/23/18
to jPOS Users
that was just an option i was trying to see if it would work/if its a good aproach because i am already giving up

chhil

unread,
Jan 23, 2018, 6:58:39 PM1/23/18
to jpos-...@googlegroups.com

I remember reading something to paralelize participants, but I’m not sure and don’t remember how.


To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/32808318-6731-4873-8680-61c1c7a34ac5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
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+unsubscribe@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.

Andrés Alcarraz

unread,
Jan 23, 2018, 7:20:52 PM1/23/18
to jpos-...@googlegroups.com

Awsome Chill thanks for refreshing my memory,  it was +10 yeas ago and never had te chance to use it, and I was lazy and in a rush when responding to look for it myself.

Best regards.

Andrés


El 23/01/18 a las 20:58, chhil escribió:

chhil

unread,
Jan 23, 2018, 9:34:50 PM1/23/18
to jpos-...@googlegroups.com
We got each other's back "Andrés :-)

-chhil

--
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

Chikodi Nwanjoku

unread,
Jan 24, 2018, 1:15:04 PM1/24/18
to jPOS Users
Thank you very much Chhil and Andres for your response, i am implementing the parallel example, but the following code below is it OK or is there a better way to handle it?


I have added the join to my transaction manager

<group name="FinancialTransaction">
     <participant class="org.jpos.transaction.participant.Join">
      <participant class="main.java.com.transaction.manager.FinancialTransactionValidateMessage" logger="Q2" />
      <participant class="main.java.com.transaction.manager.FinancialTransactionQueryRemoteHost" logger="Q2" />  
      <participant class="main.java.com.transaction.manager.FinancialTransactionQueryRemoteHostMFB" logger="Q2" />
      <participant class="main.java.com.transaction.manager.FinancialTransactionResponse" logger="Q2"/>
      </participant>
    </group>

@Override
  public int prepare(long id, Serializable context) {
    Context ctx = (Context)context;
        ISOMsg respMsghost1 = (ISOMsg)ctx.get(Constants.RESPONSE_KEY_1),    //Response key from host 1
               respMsghost2 =(ISOMsg)ctx.get(Constants.RESPONSE_KEY_2);             //Response key from host 2
        
        if(!respMsghost2 .getString(39).equals("00")){                                         ///if it is not 00 return the response code sent from host 2
            ctx.put(Constants.RESPONSE_KEY,respMsghost2 );
            return PREPARED;
        }else{
            
            if(!respMsghost1 .getString(39).equals("00")){                                   //if host2 returns 00 then check if host1 returns 00 as well else perform a reversal
                
                ISOMsg reversal = (ISOMsg) respMsghost2 .clone();
                
                try {
                    reversal.setMTI("0400");                 
                    ctx.put(Constants.RESPONSE_KEY_2,reversal);
                    return PREPARED;
                } catch (ISOException ex) {
                    Logger.getLogger(FinancialTransactionResponse.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
            
          
        }
        
        
        
       
  }

-chhil

--
--
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 post to this group, send email to jpos-...@googlegroups.com.
--
--
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 post to this group, send email to jpos-...@googlegroups.com.

--
--
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 post to this group, send email to jpos-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages