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


   确认下是否使用有误?
   
   chassis:2.1.5
   pack:0.6.0
   
   依赖包:
    <dependency>
               <groupId>org.apache.servicecomb.pack</groupId>
               <artifactId>omega-spring-starter</artifactId>
               <version>0.6.0</version>
           </dependency>
   
           <dependency>
               <groupId>org.apache.servicecomb.pack</groupId>
               <artifactId>omega-transport-resttemplate</artifactId>
               <version>0.6.0</version>
           </dependency>
   
   A 服务代码
       private static RestTemplate restTemplate = RestTemplateBuilder.create();
   
       @SagaStart(timeout=10)
       @Transactional
       public int insert(com.demo.model.TTeach record) {
           try
           {
   
               //添加学生
               TUser userInfo = new TUser();
                    userInfo.setuName(record.getName()+"-的学生");
                        userInfo.setAge(record.getAge());
   
               //RestTemplate restTemplate = (RestTemplate) 
DemoApplication.app.getBean("omegaRestTemplate");
               LinkedHashMap sayHiResult = restTemplate
                       
.postForObject("cse://getui/admin/user/addEntity.action", userInfo, 
LinkedHashMap.class);
   
               tTeachMapper.insertSelective(record);
   
               return 1;
           } catch (Throwable e)
           {
   
               throw new RuntimeException(e.getMessage(), e);
           }
       }
   
   B 服务代码
   
   @Compensable(compensationMethod="cancel")
        @Transactional
        public int insert(TUser user) {
   
                try
                {
                        //parameter checking write here please.
                        userMapper.insertSelective(user);
                        //System.out.println(4/0);
                        return 1;
                } catch (Throwable e)
                {
                        //e.printStackTrace();
                        throw new RuntimeException(e);
                }
        }
   
   
        @Transactional
        public boolean cancel(TUser user) {
   
                System.out.println("学生补偿函数"+user.getuName());
                return true;
        }
   
   B服务报错信息:
   org.apache.servicecomb.pack.omega.transaction.OmegaException: Cannot find 
the globalTxId from OmegaContext. Please using @SagaStart to start a global 
transaction.
   
   在A服务TransactionClientHttpRequestInterceptor.intercept打断点都没进。
   


----------------------------------------------------------------
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