如何从轴突禁用特定事件处理程序?

发布于 2025-01-14 05:04:30 字数 705 浏览 1 评论 0原文

我们在代码中配置了一些事件处理程序。但是,我想从轴突禁用特定的事件处理程序。

请注意 - 我可以使用 @Profile 或 @Conditional 参数来执行此操作。但是,我很想知道是否有类似 EventConfig 中的配置的方法可以从处理中排除特定的事件处理程序。

请参考下面的代码。

事件源配置

public class AxonConfig {
   
    public void configureProcessorDefault(EventProcessingConfigurer processingConfigurer) {
        processingConfigurer.usingSubscribingEventProcessors();
    }
}

事件处理程序

@ProcessingGroup("this")
class ThisEventHandler {
    // your event handlers here...
}

@ProcessingGroup("that")
class ThatEventHandler {
    // your event handlers here...
}

@ProcessingGroup("other")
class OtherEventHandler {
    // your event handlers here...
}```

We have a few event handlers configured in the code. But, I'd like to disable a particular event handler from axon.

Please note - I can do this using @Profile or @Conditional parameter. But, I am interested to know if there is any way like config at EventConfig to exclude the particular event handler from processing.

Please refer below code.

Event Source Config

public class AxonConfig {
   
    public void configureProcessorDefault(EventProcessingConfigurer processingConfigurer) {
        processingConfigurer.usingSubscribingEventProcessors();
    }
}

Event handlers

@ProcessingGroup("this")
class ThisEventHandler {
    // your event handlers here...
}

@ProcessingGroup("that")
class ThatEventHandler {
    // your event handlers here...
}

@ProcessingGroup("other")
class OtherEventHandler {
    // your event handlers here...
}```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2025-01-21 05:04:30

作为 EventProcessingConfigurer 的结果而构造的 EventProcessingConfiguration 提供了一种检索事件处理器实例的方法。此外,任何 EventProcessor 实现都有 start()shutDown() 方法。

因此,您可以停止您想要停止的事件处理器。

以下代码将为您完成此任务:

class EventProcessorControl {

    private final EventProcessingConfiguration processingConfig;

    EventProcessorControl(EventProcessingConfiguration processingConfig) {
        this.processingConfig = processingConfig;
    }

    public void startProcessor(String processorName) {
        processingConfig.eventProcessor(processorName)
                        .ifPresent(EventProcessor::start);
    }

    public void stopProcessor(String processorName) {
        processingConfig.eventProcessor(processorName)
                        .ifPresent(EventProcessor::shutDown);
    }
}

作为附注,我会警告使用SubscribingEventProcessor。在事件处理器实现中,它在性能、分发和错误处理方面提供的灵活性最少。我宁愿尝试使用 PooledStreamingEventProcessor 来代替。

The EventProcessingConfiguration that's constructed as a result of the EventProcessingConfigurer provides a means to retrieve your Event Processor instances. Furthermore, any EventProcessor implementation has a start() and shutDown() method.

You can thus stop the Event Processors that you want to stop.

The following piece of code would get that done for you:

class EventProcessorControl {

    private final EventProcessingConfiguration processingConfig;

    EventProcessorControl(EventProcessingConfiguration processingConfig) {
        this.processingConfig = processingConfig;
    }

    public void startProcessor(String processorName) {
        processingConfig.eventProcessor(processorName)
                        .ifPresent(EventProcessor::start);
    }

    public void stopProcessor(String processorName) {
        processingConfig.eventProcessor(processorName)
                        .ifPresent(EventProcessor::shutDown);
    }
}

As a side note, I would warn against only using the SubscribingEventProcessor. Of the Event Processor implementations, it provides the least amount of flexibility when it comes to performance, distribution and error handling. I'd much rather try using the PooledStreamingEventProcessor instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文