gjguanjie opened a new issue #658:
URL: https://github.com/apache/servicecomb-pack/issues/658


   使用https://hub.docker.com/r/coolbeevip/servicecomb-pack中 docker-compose.yaml 
方式启动标准镜像只包含 Alpha 服务。 含状态机了。
   客户端中引入,使用restTemplate方式
   <dependency>
               <groupId>org.apache.servicecomb.pack</groupId>
               <artifactId>omega-spring-starter</artifactId>
           </dependency>
           <dependency>
               <groupId>org.apache.servicecomb.pack</groupId>
               <artifactId>omega-transport-resttemplate</artifactId>
           </dependency>
                
   测试如下 代码如下:
   服务1:
   @RestController
   @RequestMapping("/saga")
   public class SagaController {
   
       private static final Logger LOGGER = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   
       @Resource
       private RestTemplate template;
   
       @GetMapping("/start")
       @SagaStart
       public void start() {
           LOGGER.error("调服务");
           
template.postForObject("http://localhost:9001/service/test",null,String.class);
       }
   }    
   
   服务2:
   @RestController
   @RequestMapping("service")
   public class SagaServiceController {
   
       private static final Logger LOGGER = 
LoggerFactory.getLogger(MethodHandles.lookup().getClass());
   
       @Resource
       private SagaService sagaService;
   
       @PostMapping("test")
       public void test(){
           sagaService.test();
       }
   }
   
   @Service
   public class SagaService {
   
       private static final Logger LOGGER = 
LoggerFactory.getLogger(MethodHandles.lookup().getClass());
   
       @Compensable(compensationMethod = "cancel")
       public void test() {
           int aa = 1;
           LOGGER.error("测试方法");
           int bb = 1/0;
       }
   
       public void cancel() {
           LOGGER.error("Cancel方法");
       }
   }
   
   当调用服务1接口http://localhost:9000/saga/start时,遇到服务2中报错,原则上,会调用cancel方法,但没有执行。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to