【咨询】resttemplate没有传递事务上下文。
myVictor opened this issue · 1 comments
myVictor commented
确认下是否使用有误?
chassis:2.1.5
pack:0.6.0
依赖包:
org.apache.servicecomb.pack
omega-spring-starter
0.6.0
<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打断点都没进。
myVictor commented
我都懵了,原来是在chassis环境下不行。用springboot的服务端口号访问是可以的