Today, i want to share how JPos client handle request message from remote server.
i just learn JPos ISO 8583 framework, and looking for information about it. you can find information about jpos framework on their official site here. in this post, i want to share what i have learned about JPos Client Receive Request From Remote Server.
Normally, a client is responsible for sending request and wait response from server. But in my project, the server want to send Network Management (0800 message) to my client address, because they want to know that my client is still alive and listening to their server.
after spend hours to looking for about that problem, i get a solution from JPos Programmer guide:
Under many situations, the same channel that a client application may use to send requests and wait for responses may also receive requests coming from the remote server.”
“Those unmatched requests coming from the remote server are delegated to an ISORequestListener (or a well
defined “unhandled” Space queue).”
and
If you remember QSP and ISOMUX, you might wonder how to handle incoming messages that don’t match an
outgoing request (i.e. late responses, network management messages originated by a remote server, etc.).”
The old ISOMUX had a request listener for that, but in Q2, with clusters, redundancy and scalability in mind,we use the space instead. You can configure an optional unhandled queue, and QMUX will place all arriving
messages that don’t match any pending request in that queue.
and Mark said on jpos user group:
This means that messages that you are not (or no longer) waiting for or not expecting can arrive. If they do, then the MUX will place them on the unhandled space queue.”
These might be :-
- late responses that you are no longer waiting for, since you have timed out
- network management messages that the server initiates
- responses that are not matched to your requests due to incorrect MUX key setup
- junk.
And then i realize that ISOMUX have method setISORequestListener(ISORequestListener l)
all we need is just call that method before start isoMux.
[java]
ISOMUX isoMux = isoMux = new ISOMUX(channel) {
@Override
protected String getKey(ISOMsg m) throws ISOException {
return super.getKey(m);
}
};
isoMux.setISORequestListener(new ClientRequestListener());
new Thread(isoMux).start();
[/java]
if you create JPos Client using xml, just set the blah_mux.xml like this:
[xml]
[/xml]
and finally, we have to create ClientRequestListener class that implements ISORequestListener interface.
[java]
package com.example.ISOClient;
import java.io.IOException;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISORequestListener;
import org.jpos.iso.ISOSource;
/**
* This class will listen ‘unhandled-message’ for client
* @author Didik Hari
*
*/
public class ClientRequestListener implements ISORequestListener {
public ClientRequestListener() {
super();
}
@Override
public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
ISOMsg reply = (ISOMsg) isoMsg.clone();
try {
reply.setResponseMTI();
reply.set(39, “00”);
isoSrc.send(reply);
} catch (ISOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
[/java]
Leave a Reply