0
votes

I have a java application(say A) which communicate with an application(say B) via TCP Socket. My java application is multithreaded, can handle up to 100 threads. To communicate between A --> B we have 10 sockets.

Challenges -

  1. Connection Pooling - need connection pooling mechanism to handle n(say 100) number of thread(of application A), communicating to application B via x(say 10) number of TCP Socket.

  2. Multithreading - How can two thread access same socket send the request one by one and get back the response mapped to appropriate thread.

  3. Multiple request - Is it possible that two thread can send the request on single socket simultaneously.

Can we over come this challenge via any framework? Is it possible? I heard that Spring Integration/ApacheCamel/Local MQ can resolve this solutions. Any examples.

2
I don't know why you tagged this as jpos, assuming you are trying to send ISOMsg, the components you need to use are MuxPool, QMUX and ChannelAdaptor. 1. If this is the case, I don't see why you need connection pooling to the same application but that can be achieved with N CannelAdaptors pointing to the same B application, N QMuxes and 1 MuxPool. 2. Mux will be the one that knows how to match replies with requests, you don't have to worry about concurrency. 3. It is possible, however you have to ensure messages are written atomically, if not your messages can end being scrambled.Andrés Alcarraz
@AndrésAlcarraz Yes we are communicating via ISOMsg. And I tried with jPOS library and I am able to achieve point 1 and 2.Mayank Gupta
Hi @mayank, so for point 3 MUX and ISOChannel make the synchronization for you, you don't have to worry about concurrency if you access them through the mux.request method, or the channel. send method. But regarding the channel is better if you communicate through the queues of the channel adaptor.Andrés Alcarraz
@AndrésAlcarraz Thanks. I was trying to include latest jPOS library in my project through maven, which is version 2.0.8 but it was failing due to other dependent jar version not available in repository. It was looking for below. But in repository it was not available. <dependency> <groupId>com.sleepycat</groupId> <artifactId>je</artifactId> <version>7.0.6</version> <scope>compile</scope> </dependency> jPOS : repo.maven.apache.org/maven2/org/jpos/jpos je : repo.maven.apache.org/maven2/com/sleepycat/jeMayank Gupta
You need to add oracle maven repo where the specified version of sleepycat is: <repositories> <repository> <id>oracleReleases</id> <name>Oracle Released Java Packages</name> <url>download.oracle.com/maven</url> <layout>default</layout> </repository> </repositories>Andrés Alcarraz

2 Answers

2
votes

With Spring Integration:

  1. CachingClientConnectionFactory
  2. TcpOutboundGateway (with CachingClientConnectionFactory).
  3. Collaborating Outbound and Inbound Channel Adapters.

But you have to do your own request/reply collaboration (usually based on something in the message); the replies may not come back in the order they were sent. Since there is no standard way to perform that collaboration, the framework doesn't support it itself.

0
votes

I was able to resolve the problem stated in question via jPOS.

jPOS can do multiplexing. It uses ISOMessage field 11 and 41 for matching the request and response.

jPOS also providing pooling mechanism.