6 Replies Latest reply: Mar 27, 2012 3:13 PM by Earnest Dyke RSS

JBoss as a socket client

Earnest Dyke Novice

Greetings all,

 

We are in the design process of an application that will see our JBoss AS 5 server receiving RESTFul requests and for each request acting as a client to a socket based application. The socket based app will be running on many different machines so creating a pool of sockets is not practical. My question to the community is how would we architect our application? Opening sockets within an EJB based app is a no-no so what to do? The flow is basically this:

 

RESTFul request into JBoss AS 5 app

JBoss AS 5 app opens a socket to the requested host and may make any number of transmittions back and forth.

Once the logical transaction is complete the JBoss app would close the socket and return the results as payload of the RESTFul call.

 

Any and all relevant responses are appreciated!

 

Earnie!

 

P.S. We will be migrating to AS 7 in the near future so any solution should take this into consideration.

  • 1. Re: JBoss as a socket client
    Wolf-Dieter Fink Master

    It sounds like that a JCA connector can do that for you.

    You have to implement your own connector, and if you use more that this connector in one transaction you should implement XA-transactions.

  • 2. Re: JBoss as a socket client
    Earnest Dyke Novice

    Thanks Wolf.

     

    I thouhgt of JCA but in researching it it seemed to me that JCA was more "pooling" focused and the nature of my application is that I will have 1000s of socket end points that will be opened, used then closed (maybe only once in a day). So JCA seems like overkill. Am I missing something?

     

    Earnie!

  • 3. Re: JBoss as a socket client
    Wolf-Dieter Fink Master

    I suppose that your app is stateless, so every call via socket is independent.

    That is exact what JCA is for. You open only a bunch of sockets and such connection will be reused.

    You can ensure that a socket is not reused if the transaction is running, that is a implementation detail of the JCA connector.

  • 4. Re: JBoss as a socket client
    Earnest Dyke Novice

    Wolf,

     

    I understand what you are saying but unlike a connection to a data source where there are a defined number of connections to a specific ip address/host this app will have single connections to 1000s of "hosts" none of which can be shared.

     

    Earnie!

  • 5. Re: JBoss as a socket client
    Wolf-Dieter Fink Master

    At the moment it is still unclear to me how it works.

    - a external client know internal host names?

    - open and close sockets might have a bad performance (ok, maybe not if it is not very frequent)

     

    Do you mean by 'logical transaction' that this Tx spans more than one external request? But in this case I'm not sure how you work with the socket ... stateful beans?

    So in fact there is no technical restriction that stop you handle sockets.

    But I would think about the architecture ....  (but I have not the complete picture, so it's on you)

  • 6. Re: JBoss as a socket client
    Earnest Dyke Novice

    Wolf,

     

    I have been experimenting today and you are definately correct: JCA is the correct way to do this. I have created a JCA datasource for the connections my app needs and a RESTFul service front ends the whole thing. Pretty cool!!!

     

    For clarity, we have a legacy app that needs to get digital signature from a Verifone device. The legacy app knows the ip address of the device associated with the terminal where the legacy app is running so the legacy app makes a RESTFul service call passing the ip address/port of the device. The app I am developing must then, now using a JCA, connect to the proper device over a socket connection. The logical process of signing takes a couple of requests back and forth between my app and the device. Once done, the connection is closed, and the RESTFul service returns the results.

     

    Thanks for you help!!!

     

    Earnie!