Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Axon框架与Atomikos?如何';什么工作?_Java_Oracle_Spring Boot_Axon_Atomikos - Fatal编程技术网

Java Axon框架与Atomikos?如何';什么工作?

Java Axon框架与Atomikos?如何';什么工作?,java,oracle,spring-boot,axon,atomikos,Java,Oracle,Spring Boot,Axon,Atomikos,我有一个问题,我必须在Spring引导中使用Atomikos和Axon框架(没有Axon服务器)。我正在使用Oracle DB,我正在使用多个线程(10)来发送大量命令,在此之前,我正在为自己配置一个JtaTransactionManager,但在一些线程中,我得到了这种异常:javax.transaction.xa.XAException,引发了-6或-4或-3或ORA-02056:2PC:k2lcom:错误的两阶段命令号rdonly from coord:。在调试时,我看到CommandGa

我有一个问题,我必须在Spring引导中使用Atomikos和Axon框架(没有Axon服务器)。我正在使用Oracle DB,我正在使用多个线程(10)来发送大量命令,在此之前,我正在为自己配置一个JtaTransactionManager,但在一些线程中,我得到了这种异常:javax.transaction.xa.XAException,引发了-6或-4或-3或ORA-02056:2PC:k2lcom:错误的两阶段命令号rdonly from coord:。在调试时,我看到CommandGateWay也在使用JtaTransactionManager。是这样吗?什么时候开始交易?我的JtaTransactionManager和Axon的可能有冲突吗? 有人有这种例外吗

示例代码:

@Service
public class CreateEntitiesServiceImpl extends FutureCompleter implements CreateEntitiesService {

    private static Logger logger = LoggerHelper.getDeveloperLogger(CreateEntitiesServiceImpl.class);
    private final CommandGateway commandGateway;
    private final ExecutionUtil executionUtil;
    private final MyEntityRepository myEntityRepository;

    public CreateEntitiesServiceImpl(CommandGateway commandGateway, ExecutionUtil executionUtil, MyEntityRepository myEntityRepository) {
        this.commandGateway = commandGateway;
        this.executionUtil = executionUtil;
        this.myEntityRepository = myEntityRepository;
    }

    @Override
    public void process(Message message) {
        logger.info("Entity addition started!");
        generateEntities();
        logger.info("Entity addition finished!");
    }

    private void generateEntities() {
        ExecutorService executorService = executionUtil.createExecutor(10, "createEntities");

        List<Integer> list = IntStream.rangeClosed(1, 1000).boxed().collect(Collectors.toList());

        CreateEntitiesService proxy = applicationContext.getBean(CreateEntitiesServiceImpl.class);

        List<CompletableFuture<Void>> processingFutures = list.stream().map(
                e -> CompletableFuture.runAsync(proxy::createEntity, executorService).whenComplete((x, y) -> executorService.shutdown()))
                .collect(Collectors.toList());

        processingFutures.stream().map(this::getVoidFuture).collect(Collectors.toList());
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void createEntity() {
        try {
            MyEntity myEntity = new MyEntity();
            myEntity.setEntityStringProperty("string");
            myEntity.setEntityTimestampProperty(LocalDateTime.now());

            MyEntity savedEntity = myEntityRepository.save(myEntity);
            CreateAggregateCommand command = new CreateAggregateCommand(savedEntity.getEntityId(), savedEntity.getEntityStringProperty(),
                    savedEntity.getEntityTimestampProperty());
            commandGateway.send(command);
        } catch (Exception e) {
            throw new CreateEntitiesException(e.getMessage(), e);
        }
    }
}
@服务
公共类CreateEntitiesServiceImpl扩展FutureCompleter实现CreateEntitiesService{
私有静态记录器Logger=LoggerHelper.getDeveloperLogger(CreateEntitiesServiceImpl.class);
私有最终命令网关命令网关;
私有最终执行util ExecutionUtil;
私人终末髓鞘再生髓鞘再生;
公共CreateEntitiesServiceImpl(CommandGateway CommandGateway、ExecutionUtil ExecutionUtil、MyEntityRepository MyEntityRepository){
this.commandGateway=commandGateway;
this.executionUtil=executionUtil;
this.myEntityRepository=myEntityRepository;
}
@凌驾
公共作废流程(消息){
info(“实体添加已开始!”);
生成性();
logger.info(“实体添加完成!”);
}
私有无效生成属性(){
ExecutorService ExecutorService=executionUtil.createExecutor(10,“createEntities”);
List List=IntStream.rangeClosed(11000.boxed().collect(Collectors.toList());
CreateEntitiesService proxy=applicationContext.getBean(CreateEntitiesServiceImpl.class);
List processingFutures=List.stream().map(
e->CompletableFuture.runAsync(代理::createEntity,executorService).whenComplete((x,y)->executorService.shutdown())时
.collect(Collectors.toList());
processingFutures.stream().map(this::getVoidFuture.collect(Collectors.toList());
}
@事务性(传播=传播。需要\u新建)
public void createEntity(){
试一试{
MyEntity MyEntity=新的MyEntity();
myEntity.setEntityStringProperty(“字符串”);
myEntity.setEntityTimestampProperty(LocalDateTime.now());
MyEntity savedEntity=myEntityRepository.save(MyEntity);
CreateAggregateCommand命令=新建CreateAggregateCommand(savedEntity.getEntityId(),savedEntity.getEntityStringProperty(),
savedEntity.getEntityTimestampProperty());
commandGateway.send(命令);
}捕获(例外e){
抛出新的CreateEntityException(e.getMessage(),e);
}
}
}

谢谢

老实说,我不完全理解你的要求

标题用Atomikos来描述Axon,而我觉得这一点在描述中再也没有出现过

您在问题描述中询问的是
CommandGateway
使用事务管理器是否正确

在这件事上,我可以说得很清楚:是的。 发送命令很可能会导致您陷入聚合实例中。由于您希望保护此实例中的一致性边界,并确保发布的事件得到存储,因此在处理命令时立即启动事务是明智的

顺便说一句,小提示:它是使用
TransactionManager
CommandBus
。从概念上讲,到目前为止,这并没有改变我的描述

最后,我不完全确定这是否会帮助你,因为我对你的问题并不完全清楚。我希望你的文章重写后能澄清更多你真正想要的东西