使用 ChannelAdaptor 和 QMUX 发送 iso 消息的问题
Posted
技术标签:
【中文标题】使用 ChannelAdaptor 和 QMUX 发送 iso 消息的问题【英文标题】:Problem with sending iso message using ChannelAdaptor & QMUX 【发布时间】:2020-07-30 04:37:54 【问题描述】:我正在使用通道适配器和 qmux 将 iso8583 消息发送到套接字服务器。
我在 netbeans 中编写了 2 个 maven 项目 Jpos 客户端和服务器。
服务器接受连接但没有收到消息(或客户端不发送消息)但是当我取消客户端项目的进程时,服务器收到
如果我错了,请纠正我。
以下是我的配置文件(参考http://jpos.org/doc/proguide-draft.pdf)
10_channel.xml
<?xml version="1.0" encoding="UTF-8"?>
<channel-adaptor name='test-channel'
class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel class="org.jpos.iso.channel.ASCIIChannel" logger="Q2" realm="test-channel"
packager="org.jpos.iso.packager.GenericPackager">
<property name="packager-config" value="src/main/resources/iso8583.xml" />
<property name="host" value="127.0.0.1" />
<property name="port" value="9090" />
<property name="connection-timeout" value="15000" />
<property name="timeout" value="3000000" />
<property name="keep-alive" value="true" />
</channel>
<!-- <ignore-iso-exceptions>yes</ignore-iso-exceptions>-->
<in>client-send</in>
<out>client-receive</out>
<reconnect-delay>10000</reconnect-delay>
</channel-adaptor>
20_mux.xml
<?xml version="1.0" encoding="UTF-8"?>
<mux class="org.jpos.q2.iso.QMUX" logger="Q2" name="test-mux">
<in>client-receive</in>
<out>client-send</out>
<ready>test-channel.ready</ready>
<unhandled>myunhandledqueue</unhandled>
<key>2 7</key>
</mux>
JPos 客户端代码
Q2 q2 = new Q2("src/main/deploy/");
q2.start();
QMUX mux = (QMUX)NameRegistrar.getIfExists("mux.test-mux");
if (mux != null && mux.isConnected())
ISOMsg request = new IsoMessage().build(); //dump iso message
ISOMsg response = mux.request(request, REQUEST_TIMEOUT);
if (response != null)
ISOMsg receivedIsoMsg = new ISOMsg();
receivedIsoMsg.setPackager(new GenericPackager("path_to_file_xml"));
receivedIsoMsg.unpack(response.getBytes());
receivedIsoMsg.dump(System.out, "");
套接字服务器代码
ServerSocket serverSocket;
try
System.out.println("Binding to port " + SERVER_PORT + ", please wait ...");
serverSocket = new ServerSocket(SERVER_PORT);
System.out.println("Server started: " + serverSocket);
System.out.println("Waiting for a client ...");
while (true)
try
Socket socket = serverSocket.accept();
DataInputStream dis = new DataInputStream(socket.getInputStream());
String message = (String) dis.readLine();
System.out.println("Message Received: " + message);
ISOMsg receivedIsoMsg = new ISOMsg();
receivedIsoMsg.setPackager(new GenericPackager("path_to_file_xml"));
receivedIsoMsg.unpack(message.getBytes());
receivedIsoMsg.setMTI("0110");
receivedIsoMsg.set(39,"00");
receivedIsoMsg.dump(System.out, "");
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
//write object to Socket
dos.writeUTF(new String(receivedIsoMsg.pack()));
catch (IOException | ISOException ex)
System.err.println(ex);
catch (IOException e1)
try
serverSocket.close();
catch (IOException ex)
System.err.println(ex);
跟踪日志 客户:
--- exec-maven-plugin:1.2.1:exec (default-cli) @ JposTest ---
<log realm="Q2.system" at="2020-07-30T10:45:25.638">
<info>
Q2 started, deployDir=/Users/lap/NetBeansProjects/JposTest/src/main/deploy, environment=default
</info>
</log>
<log realm="Q2.system" at="2020-07-30T10:45:26.160" lifespan="507ms">
<version>
jPOS 2.1.3 master/95b8dce (2019-06-16 15:16:57 ART)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
jPOS Community Edition, licensed under GNU AGPL v3.0.
This software is probably not suitable for commercial use.
Please see http://jpos.org/license for details.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iQEcBAEBAgAGBQJMolHDAAoJEOQyeO71nYtFv74H/3OgehDGEy1VXp2U3/GcAobg
HH2eZjPUz53r38ARPiU3pzm9LwDa3WZgJJaa/b9VrJwKvbPwe9+0kY3gScDE1skT
ladHt+KHHmGQArEutkzHlpZa73RbroFEIa1qmN6MaDEHGoxZqDh0Sv2cpvOaVYGO
St8ZaddLBPC17bSjAPWo9sWbvL7FgPFOHhnPmbeux8SLtnfWxXWsgo5hLBanKmO1
1z+I/w/6DL6ZYZU6bAJUk+eyVVImJqw0x3IEElI07Nh9MC6BA4iJ77ejobj8HI2r
q9ulRPEqH9NR79619lNKVUkE206dVlXo7xHmJS1QZy5v/GT66xBxyDVfTduPFXk=
=oP+v
-----END PGP SIGNATURE-----
</version>
</log>
<log realm="Q2.system" at="2020-07-30T10:45:26.168" lifespan="5ms">
<info>
deploy: /Users/lap/NetBeansProjects/JposTest/src/main/deploy/10_zp_channel.xml
</info>
</log>
<log realm="Q2.system" at="2020-07-30T10:45:26.199" lifespan="30ms">
<info>
deploy: /Users/lap/NetBeansProjects/JposTest/src/main/deploy/20_zp_qmux.xml
</info>
</log>
<log realm="Q2.system" at="2020-07-30T10:45:26.207" lifespan="8ms">
<info>
deploy: /Users/lap/NetBeansProjects/JposTest/src/main/deploy/99_sysmon.xml
</info>
</log>
<log realm="org.jpos.q2.qbean.SystemMonitor" at="2020-07-30T10:45:26.225">
<info>
Starting SystemMonitor
</info>
</log>
<log realm="org.jpos.q2.qbean.SystemMonitor" at="2020-07-30T10:45:26.225">
<info>
......
thread count: 10
peak threads: 10
user threads: 7
Thread[Reference Handler,10,system]
Thread[Finalizer,8,system]
Thread[Signal Dispatcher,9,system]
Thread[main,5,main]
Thread[pool-1-thread-1,5,main]
Thread[Q2-dd666708-34a1-46dc-9a10-4df253d9249a,5,main]
Thread[Thread-1,5,main]
Thread[channel-sender-client-send,5,main]
Thread[channel-receiver-client-receive,5,main]
Thread[SystemMonitor,5,main]
name-registrar:
tspace:default: org.jpos.space.TSpace
key-count: 0
gcinfo: 0,0
Q2: org.jpos.q2.Q2
test-channel: org.jpos.q2.iso.ChannelAdaptor
tx=0, rx=0, connects=0, last=0
logger.Q2: org.jpos.util.Logger
channel.test-channel: org.jpos.iso.channel.ASCIIChannel
mux.test-mux: org.jpos.q2.iso.QMUX
tx=0, rx=0, tx_expired=0, tx_pending=0, rx_expired=0, rx_pending=0, rx_unhandled=0, rx_forwarded=0, connected=false, last=0
logger.: org.jpos.util.Logger
</info>
</log>
<log realm="test-channel/127.0.0.1:9090" at="2020-07-30T10:45:36.309" lifespan="10084ms">
<connect>
Try 0 127.0.0.1:9090
</connect>
</log>
<log realm="test-channel/127.0.0.1:9090" at="2020-07-30T10:45:55.579" lifespan="1ms">
<send>
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[src/main/resources/iso8583.xml] -->
<field id="0" value="0100"/>
<field id="2" value="123456"/>
<field id="3" value="000010"/>
<field id="4" value="1500"/>
<field id="7" value="1206041200"/>
<field id="11" value="000001"/>
<field id="41" value="12340001"/>
<field id="49" value="840"/>
</isomsg>
</send>
</log>
服务器:
--- exec-maven-plugin:1.2.1:exec (default-cli) @ AppTest ---
Binding to port 9090, please wait ...
Server started: ServerSocket[addr=0.0.0.0/0.0.0.0,localport=9090]
Waiting for a client ...
Client accepted: Socket[addr=/127.0.0.1,port=58902,localport=9090]
=> 客户端无法发送消息 但是如果我取消客户端项目的过程,服务器会收到消息并打印日志:
Message Received: 00730100722000000080800006123456000010000000001500120604120000000112340001840
<isomsg>
<!-- org.jpos.iso.packager.GenericPackager -->
<field id="0" value="0110"/>
<field id="8" value="80000612"/>
<field id="18" value="3456"/>
<field id="19" value="000"/>
<field id="20" value="010"/>
<field id="23" value="000"/>
<field id="27" value="0"/>
<field id="39" value="00"/>
<field id="57" value=""/>
</isomsg>
【问题讨论】:
【参考方案1】:问题是您尝试使用 readLine
接收消息,而 iso 消息不是以 EOL 结尾的字符串。
我相信发生的事情是,当客户端断开连接时,readLine
方法返回,因为输入流已关闭。
最好在您的服务器上使用ISOServer
,或者更好地使用完整的q2
来实现它。
否则,您应该先读取消息长度,然后从输入流中读取相应数量的字节,而不是等待可能是也可能不是消息本身一部分的换行符
您可以在http://www.jpos.org/tutorials 处遵循前两个 jpos 教程,了解如何使用请求侦听器配置服务器以处理请求。
【讨论】:
谢谢。我已经尝试按照您的建议进行操作,并且奏效了。 :D以上是关于使用 ChannelAdaptor 和 QMUX 发送 iso 消息的问题的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 php 和 mysql 使用纬度和经度进行几何搜索
Cocoa - 为啥使用 NSInteger 和 CGFloat 而不是使用 int 和 float,或者总是使用 NSNumber?