简体   繁体   English

如何使Web服务的调用链具有事务性?

[英]How to make a chain of calls of Web services transactional?

Let's says that I want to make two calls: one to service A and the second one to service B . 假设我要打两个电话:一个打给A服务,第二个打给B服务。

How should I make those two calls in a transactional way ? 我该如何以交易方式拨打这两个电话? For example, I call service A (it inserts some data into DB) and after that I try to call service B , but this fails; 例如,我呼叫服务A (它将一些数据插入DB),然后尝试呼叫服务B ,但这失败了。 how should I rollback the insertion made when I called the service A ? 我应该如何回滚在调用服务A时所做的插入?

Should I call a "rollback" method? 我应该调用“回滚”方法吗?

What if also this call will not work? 如果此呼叫也无法使用怎么办?

Spring framework provides an abstract layer on top of different underlying transaction management APIs. Spring框架在不同的基础事务管理API之上提供了一个抽象层。

Read this: http://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html 阅读此内容: http : //docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html

@Transactional(readOnly = true)
public class DefaultFooService implements FooService {

    public Foo getFoo(String fooName) {
        // do something
    }

    // these settings have precedence for this method
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public void updateFoo(Foo foo) {
        // do something
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM