【问题标题】:Spring State Machine弹簧状态机
【发布时间】:2017-12-28 17:56:31
【问题描述】:
    public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception {
    config
            .withConfiguration()
            .machineId("test")
            .autoStartup(false)
            .listener(listener());
    }

此代码段允许我设置一台 ID 为“test”的机器,但如果我想在一个环境中工作,在该环境中我可以在启动之前根据某些参数使用一些 UUID 唯一标识我的每台机器,我该怎么做?与事件共享相同,以便当它返回时将启动相同的状态机

    public void start(Request incomingRequest) {

    WorkflowInstance instance = new WorkflowInstance();
    instance.setSomeMessage(incomingRequest.getMessage());
    instance = workflowInstanceRepository.save(instance); //This will generate an UUID which I want to use to get my machine everytime I am coming back and changing the transition
    //ID should be taken from the config? or how as each one will have a separate data
    StateMachine<States, Events> stateMachine = factory.getStateMachine();
    stateMachine.start();
    Message<Events> message = MessageBuilder
            .withPayload(Events.INITIALIZING)
            .setHeader("message", incomingRequest).build();
    stateMachine.sendEvent(message);
   }

【问题讨论】:

    标签: spring spring-statemachine


    【解决方案1】:

    您不需要在配置中设置机器ID,而是可以使用工厂设置它:

    思想工厂不会保留这些机器,并且每次都会返回新实例,因为它只允许设置机器 id。

    StateMachine<States, Events> stateMachine = factory.getStateMachine("test");

    下一个版本1.2.8 将有一些额外的设施来帮助管理正在运行的机器,因为看起来这就是您想要在此处执行的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2021-01-28
      相关资源
      最近更新 更多