Open XiaoMaoGuai opened 3 years ago
springcloud的demo 1、hosts文件还得改 2、日志也搞不清为啥非得放文件里,直接输出到控制台不行吗? demo真是不够demo,开箱不能即用
2021-06-10 18:21:39,683 ERROR [http-nio-7070-exec-1] - [org.bytesoft.bytetcc.supports.springcloud.controller.CompensableCoordinatorController] - Error occurred while rolling back transaction: 7654958be40243dc3bb963039f80379d. javax.transaction.xa.XAException: null at org.bytesoft.bytetcc.CompensableCoordinator.invokeRollback(CompensableCoordinator.java:399) at org.bytesoft.bytetcc.CompensableCoordinator.rollback(CompensableCoordinator.java:366) at org.bytesoft.bytetcc.supports.springcloud.controller.CompensableCoordinatorController.rollback(CompensableCoordinatorController.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.cloud.sleuth.instrument.web.ExceptionLoggingFilter.doFilter(ExceptionLoggingFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at brave.servlet.TracingFilter.doFilter(TracingFilter.java:86) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:155) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:123) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
你说的这些,也算不上是代码有问题吧?
springcloud的demo 1、hosts文件还得改
- 早期springcloud发布的demo也需要改hosts,byteTCC的springcloud的样例直接拷贝了这种方式,后续没再调整而已。 2、日志也搞不清为啥非得放文件里,直接输出到控制台不行吗?
- 日志打印在日志文件,这种做法不能理解?这可能算个人喜好问题吧,我本人更喜欢控制台少打印一些无关的信息:byteTCC-sample除了显式打印一些显示业务/确认/取消在进行的信息外,控制台基本上比较清爽。作为demo而言,很方便看到调试效果。 demo真是不够demo,开箱不能即用
开源项目发布出来,是本着一起交流的目的。有好的想法愿意提出来,大家可以一起完善。有问题解决问题,只是没有必要象本issue这样抱有太多负面情绪。
你说的这些,也算不上是代码有问题吧?
springcloud的demo 1、hosts文件还得改
- 早期springcloud发布的demo也需要改hosts,byteTCC的springcloud的样例直接拷贝了这种方式,后续没再调整而已。 2、日志也搞不清为啥非得放文件里,直接输出到控制台不行吗?
- 日志打印在日志文件,这种做法不能理解?这可能算个人喜好问题吧,我本人更喜欢控制台少打印一些无关的信息:byteTCC-sample除了显式打印一些显示业务/确认/取消在进行的信息外,控制台基本上比较清爽。作为demo而言,很方便看到调试效果。 demo真是不够demo,开箱不能即用
开源项目发布出来,是本着一起交流的目的。有好的想法愿意提出来,大家可以一起完善。有问题解决问题,只是没有必要象本issue这样抱有太多负面情绪。
好吧,只能说每个人想法不一样,不过看过源码后,您的代码写的风格还是挺舒服的,对新手来说很友好,只不过demo就不是那么友好了
TestController:
package com.example.bytetcc.controller;
import com.example.bytetcc.service.ITransferService;
import org.bytesoft.compensable.Compensable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Compensable(interfaceClass = ITransferService.class, cancellableKey = "transferServiceCancel")
@RestController
public class TestController {
@ResponseBody
@RequestMapping("test")
@Transactional
public void test() {
System.out.println("HTTP request to decreaseAmount");
int i = 1 / 0;
System.out.println("UPDATE account SET amount = amount + 1 WHERE account_id = 1");
System.out.println("transfer done");
}
}
TransferServiceCancel:
package com.example.bytetcc.service.impl;
import com.example.bytetcc.service.ITransferService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("transferServiceCancel")
public class TransferServiceCancel implements ITransferService {
@Override
@Transactional
public void transferAmount() {
System.out.println("UPDATE account SET amount = amount - 1 WHERE account_id = 1");
}
}
ITransferService:
package com.example.bytetcc.service;
public interface ITransferService {
void transferAmount();
}
SpringBootBootstrap:
package com.example.bytetcc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
@SpringBootApplication(
scanBasePackages = "com.example.bytetcc",
exclude = MongoAutoConfiguration.class)
public class SpringBootBootstrap {
private static final Logger log = LoggerFactory.getLogger(SpringBootBootstrap.class);
public static void main(String[] args) {
SpringApplication application = new SpringApplication(SpringBootBootstrap.class);
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
log.info("springboot consumer start success");
}
}
TestController:
package com.example.bytetcc.controller; import com.example.bytetcc.service.ITransferService; import org.bytesoft.compensable.Compensable; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @Compensable(interfaceClass = ITransferService.class, cancellableKey = "transferServiceCancel") @RestController public class TestController { @ResponseBody @RequestMapping("test") @Transactional public void test() { System.out.println("HTTP request to decreaseAmount"); int i = 1 / 0; System.out.println("UPDATE account SET amount = amount + 1 WHERE account_id = 1"); System.out.println("transfer done"); } }
TransferServiceCancel:
package com.example.bytetcc.service.impl; import com.example.bytetcc.service.ITransferService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service("transferServiceCancel") public class TransferServiceCancel implements ITransferService { @Override @Transactional public void transferAmount() { System.out.println("UPDATE account SET amount = amount - 1 WHERE account_id = 1"); } }
ITransferService:
package com.example.bytetcc.service; public interface ITransferService { void transferAmount(); }
SpringBootBootstrap:
package com.example.bytetcc; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; @SpringBootApplication( scanBasePackages = "com.example.bytetcc", exclude = MongoAutoConfiguration.class) public class SpringBootBootstrap { private static final Logger log = LoggerFactory.getLogger(SpringBootBootstrap.class); public static void main(String[] args) { SpringApplication application = new SpringApplication(SpringBootBootstrap.class); application.setBannerMode(Banner.Mode.OFF); application.run(args); log.info("springboot consumer start success"); } }
运行后,调用test HTTP接口,报错了,但是没有触发cancel方法,这是为什么呢?
HTTP request to decreaseAmount
2022-01-26 14:48:35.876 ERROR 52996 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ArithmeticException: / by zero] with root cause
java.lang.ArithmeticException: / by zero
at com.example.bytetcc.controller.TestController.test(TestController.java:19) ~[main/:na]
at com.example.bytetcc.controller.TestController$$FastClassBySpringCGLIB$$2252452d.invoke(<generated>) ~[main/:na]
全局事务回滚情况下,也并非每个TCC服务的cancel都需要被调用。如果byteTCC可以通过本地事务回滚将该服务撤回,后续就不再调用其cancel了。 详细请参考 用户指南 中"3.3、TCC型服务Cancel业务定义"章节的注意说明。
demo的哪个工程跑不起来?提示什么错误?你这issue发出来,好像是遇到什么问题了但是啥都没说,然后就直接指责了,你希望达到什么效果?纯粹就是抱怨么?issue区还是尽量有问题说问题吧。