transactions with an outside resource(db/j2ee server/...)

Discussions

EJB design: transactions with an outside resource(db/j2ee server/...)

  1. Hi!

    I have a little design issue I would like to receive feedback on. My app has to work with an outside resource;by outside I mean situated in another LAN/WAN.
    All I know about this resource is that is working as a black box. However the data passed through is very important and delicate.
    This for an example as a bank to which the app has to give orders (withdraw/deposit) and has to be sure that the orders are followed correctly.

    This is somewhat new to me and I would like to know some ideas or approaches to this situation.
    I am considering the worst scenario :

    1. the link may fall down
    2. the bank may not respond
    3. something goes wrong basically

    Basically, this is a transactional service that has to go through a wire and even worst that has to be customized - ie rollback,commit may have to be translated.

    Thanks a lot!
  2. One of the ways of addressing the problem is to commit/rollback your transaction based on the type of response you get from the external resource.

    For example, if you are calling that resource from a session EJB (using container managed transactions) and exexuting following steps:

    Start of transaction
    (1) Operation 1 (Using internal resource)

    (2) Operation 2 (Using Internal resource)

    (3) operation 4 (Using external resource)

    Based on the kind of response from the external resource (which your custom code will have to interpret), you can ehither commit or roll back the transaction.

    if(response == failure)
    {

       throw new EJBException()
    }

    Optionally you can throw a checked exception after caling SessionContext.setRollbackOnly().
    You can use a similar strategy even if you are not calling from an ejb.
  3. First of all thanks for the reply.

    I was thinking the same way but I am trying to find the most elegant way to handle this type of things. Because the outside resource may not responde I am put in a very strange situation - I have to query the resource and then take appropriate steps.
    This tends to get hairy and suddenly I have a lot of things to look for.
    Ofc, this is with tight integration with my app server(i am using JBoss 3.0.x for example).

    One idea is to make a connector that maps exactly to the infrastructure and to integrate this in to the container and treat it as a resource with transaction.
    However, this only decouples things and I still have to take care of the business logic. Transaction recovery is what I am worried about ....

    Anyway, thanks for the clue...