You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by rouble <r....@gmail.com> on 2012/02/06 21:30:28 UTC

How do people implement transactions with CXF?

CXF Gurus, and Users,

How are developers implementing SOAP web services that are
transactional. For instance, if I have a bank web service that does:
api call: debit savings $10
api call: credit checkings $10

I need to be able to begin a transaction before the api calls, and
commit it after. If either one of the apis fails, I need to be able to
rollback.

I understand there are standards such WS-AtomicTransaction,
WS-Coordination and such. But how are people implementing these kinds
of functions in the absence of those standards being implemented in
CXF?

Obviously, one way would be to re-write the above api calls as one api call:
api call: transfter savings checkings $10

But that is not always an option depending on the API.

tia,
rouble

Re: How do people implement transactions with CXF?

Posted by rouble <r....@gmail.com>.
Hi Oliver,

Agreed, that this problem can be averted by using proper service design.

However, in some instances we need to be able to expose fine grained
APIs - I am trying to understand what is the best current practice of
dealing with that situation.

Cheers
rouble

On Mon, Feb 6, 2012 at 4:57 PM, Oliver Wulff <ow...@talend.com> wrote:
> Hi rouble
>
> I try to avoid to increase the complexity of my web services based integration whereever possible. I don't want to manage the transaction context within web service consumers.
>
> The example you make is a good candidate. You can avoid the situation by a proper service design. Design less fine grained operations and instead define an operation like "transfer x amount of money from acount y to acount z". Deploy your service implementation within tomcat/jee using spring and JTA and JPA and you get ACID. Transaction demarcation is on the server side (scales) and it is ensured that either the transfer is done or not and your DB is in a consistent state.
>
> What do you think?
>
> Thanks
>
>
>
> ------
>
> Oliver Wulff
>
> http://owulff.blogspot.com
> Solution Architect
> Talend Application Integration Division http://www.talend.com
>
> ________________________________________
> Von: rouble@gmail.com [rouble@gmail.com]&quot; im Auftrag von &quot;rouble [r.ouble@gmail.com]
> Gesendet: Montag, 6. Februar 2012 21:30
> Bis: users@cxf.apache.org
> Betreff: How do people implement transactions with CXF?
>
> CXF Gurus, and Users,
>
> How are developers implementing SOAP web services that are
> transactional. For instance, if I have a bank web service that does:
> api call: debit savings $10
> api call: credit checkings $10
>
> I need to be able to begin a transaction before the api calls, and
> commit it after. If either one of the apis fails, I need to be able to
> rollback.
>
> I understand there are standards such WS-AtomicTransaction,
> WS-Coordination and such. But how are people implementing these kinds
> of functions in the absence of those standards being implemented in
> CXF?
>
> Obviously, one way would be to re-write the above api calls as one api call:
> api call: transfter savings checkings $10
>
> But that is not always an option depending on the API.
>
> tia,
> rouble

AW: How do people implement transactions with CXF?

Posted by Oliver Wulff <ow...@talend.com>.
Hi rouble

I try to avoid to increase the complexity of my web services based integration whereever possible. I don't want to manage the transaction context within web service consumers. 

The example you make is a good candidate. You can avoid the situation by a proper service design. Design less fine grained operations and instead define an operation like "transfer x amount of money from acount y to acount z". Deploy your service implementation within tomcat/jee using spring and JTA and JPA and you get ACID. Transaction demarcation is on the server side (scales) and it is ensured that either the transfer is done or not and your DB is in a consistent state.

What do you think?

Thanks 



------

Oliver Wulff

http://owulff.blogspot.com
Solution Architect
Talend Application Integration Division http://www.talend.com

________________________________________
Von: rouble@gmail.com [rouble@gmail.com]&quot; im Auftrag von &quot;rouble [r.ouble@gmail.com]
Gesendet: Montag, 6. Februar 2012 21:30
Bis: users@cxf.apache.org
Betreff: How do people implement transactions with CXF?

CXF Gurus, and Users,

How are developers implementing SOAP web services that are
transactional. For instance, if I have a bank web service that does:
api call: debit savings $10
api call: credit checkings $10

I need to be able to begin a transaction before the api calls, and
commit it after. If either one of the apis fails, I need to be able to
rollback.

I understand there are standards such WS-AtomicTransaction,
WS-Coordination and such. But how are people implementing these kinds
of functions in the absence of those standards being implemented in
CXF?

Obviously, one way would be to re-write the above api calls as one api call:
api call: transfter savings checkings $10

But that is not always an option depending on the API.

tia,
rouble

Re: How do people implement transactions with CXF?

Posted by Christian Schneider <ch...@die-schneider.net>.
When you use spring then you mark the service method as @Transactional. 
So the method marks the begin and end of the transaction. So at the end 
of the transaction
the jms message is either committed or rolled back. If the service 
accesses a databases then the database transaction is also taking part 
in the transaction.

Using jta you can have transactions that span more than one service. The 
problem is that this does not really scale well as the central 
transaction management can negate the effect of additional servers or 
threads.

Christian


Am 06.02.2012 23:14, schrieb rouble:
> Hi Christian,
>
> Thanks for the comments. One thing I am missing is how is the
> beginning of a transaction indicated via a SOAP web service? Or the
> committing of a transaction?
>
> tia,
> rouble
>
> On Mon, Feb 6, 2012 at 4:23 PM, Christian Schneider
> <ch...@die-schneider.net>  wrote:
>> One way is to use SOAP/JMS where transactions should work. If you combine
>> this with a JTA transaction you should be able to get real transactional
>> behaviour.
>>
>> One problem with http is that you do not even have guaranteed delivery. For
>> example you might send a request, then the connection breaks and still the
>> call will
>> do it愀 effect. A very important best practice here is to use idempotent
>> service contracts. So you can retry the call and it will only be executed
>> once. For example you can create a unique id before the call. So if the call
>> fails to return a result but has an effect on the server you can retry and
>> the second call can be ignored by the server.
>>
>> If rollbacks need to be done only very seldomly you can do them manually.
>> You just log the failure for a human to correct the problem. This sounds
>> weird for us developers but is quite common in business.
>>
>> Christian
>>
>>
>>
>> Am 06.02.2012 21:30, schrieb rouble:
>>
>>> CXF Gurus, and Users,
>>>
>>> How are developers implementing SOAP web services that are
>>> transactional. For instance, if I have a bank web service that does:
>>> api call: debit savings $10
>>> api call: credit checkings $10
>>>
>>> I need to be able to begin a transaction before the api calls, and
>>> commit it after. If either one of the apis fails, I need to be able to
>>> rollback.
>>>
>>> I understand there are standards such WS-AtomicTransaction,
>>> WS-Coordination and such. But how are people implementing these kinds
>>> of functions in the absence of those standards being implemented in
>>> CXF?
>>>
>>> Obviously, one way would be to re-write the above api calls as one api
>>> call:
>>> api call: transfter savings checkings $10
>>>
>>> But that is not always an option depending on the API.
>>>
>>> tia,
>>> rouble
>>
>>
>> --
>> Christian Schneider
>> http://www.liquid-reality.de
>>
>> Open Source Architect
>> Talend Application Integration Division http://www.talend.com
>>


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: How do people implement transactions with CXF?

Posted by rouble <r....@gmail.com>.
Hi Christian,

Thanks for the comments. One thing I am missing is how is the
beginning of a transaction indicated via a SOAP web service? Or the
committing of a transaction?

tia,
rouble

On Mon, Feb 6, 2012 at 4:23 PM, Christian Schneider
<ch...@die-schneider.net> wrote:
> One way is to use SOAP/JMS where transactions should work. If you combine
> this with a JTA transaction you should be able to get real transactional
> behaviour.
>
> One problem with http is that you do not even have guaranteed delivery. For
> example you might send a request, then the connection breaks and still the
> call will
> do it愀 effect. A very important best practice here is to use idempotent
> service contracts. So you can retry the call and it will only be executed
> once. For example you can create a unique id before the call. So if the call
> fails to return a result but has an effect on the server you can retry and
> the second call can be ignored by the server.
>
> If rollbacks need to be done only very seldomly you can do them manually.
> You just log the failure for a human to correct the problem. This sounds
> weird for us developers but is quite common in business.
>
> Christian
>
>
>
> Am 06.02.2012 21:30, schrieb rouble:
>
>> CXF Gurus, and Users,
>>
>> How are developers implementing SOAP web services that are
>> transactional. For instance, if I have a bank web service that does:
>> api call: debit savings $10
>> api call: credit checkings $10
>>
>> I need to be able to begin a transaction before the api calls, and
>> commit it after. If either one of the apis fails, I need to be able to
>> rollback.
>>
>> I understand there are standards such WS-AtomicTransaction,
>> WS-Coordination and such. But how are people implementing these kinds
>> of functions in the absence of those standards being implemented in
>> CXF?
>>
>> Obviously, one way would be to re-write the above api calls as one api
>> call:
>> api call: transfter savings checkings $10
>>
>> But that is not always an option depending on the API.
>>
>> tia,
>> rouble
>
>
>
> --
> Christian Schneider
> http://www.liquid-reality.de
>
> Open Source Architect
> Talend Application Integration Division http://www.talend.com
>

Re: How do people implement transactions with CXF?

Posted by Christian Schneider <ch...@die-schneider.net>.
One way is to use SOAP/JMS where transactions should work. If you 
combine this with a JTA transaction you should be able to get real 
transactional behaviour.

One problem with http is that you do not even have guaranteed delivery. 
For example you might send a request, then the connection breaks and 
still the call will
do it´s effect. A very important best practice here is to use idempotent 
service contracts. So you can retry the call and it will only be 
executed once. For example you can create a unique id before the call. 
So if the call fails to return a result but has an effect on the server 
you can retry and the second call can be ignored by the server.

If rollbacks need to be done only very seldomly you can do them 
manually. You just log the failure for a human to correct the problem. 
This sounds weird for us developers but is quite common in business.

Christian



Am 06.02.2012 21:30, schrieb rouble:
> CXF Gurus, and Users,
>
> How are developers implementing SOAP web services that are
> transactional. For instance, if I have a bank web service that does:
> api call: debit savings $10
> api call: credit checkings $10
>
> I need to be able to begin a transaction before the api calls, and
> commit it after. If either one of the apis fails, I need to be able to
> rollback.
>
> I understand there are standards such WS-AtomicTransaction,
> WS-Coordination and such. But how are people implementing these kinds
> of functions in the absence of those standards being implemented in
> CXF?
>
> Obviously, one way would be to re-write the above api calls as one api call:
> api call: transfter savings checkings $10
>
> But that is not always an option depending on the API.
>
> tia,
> rouble


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com