创建多个订户/服务激活器以编程方式弹出频道

时间:2018-11-05 23:01:54

标签: java spring spring-integration

我试图在我的应用程序中利用Spring集成SI,以编程方式创建渠道和服务激活程序,我有两个问题,首先是在服务激活程序处理方法中执行消息处理的逻辑,是反模式吗?

@Component
public abstract class IChannelProcessor {

    @Loggable
    Logger logger;

    public void handleMessage(Message<IMessage> message) {

        try {

            boolean messagePreprocessed = false, messageProcessed = false, messagePostprocessed = false;

            messagePreprocessed = preProcessMessage(message);
            if (messagePreprocessed)
                messageProcessed = processMessage(message);
            if (messageProcessed)
                messagePostprocessed = postProcessMessage(message);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
        }
    }

    public abstract boolean preProcessMessage(Message<IMessage> message);

    public abstract boolean processMessage(Message<IMessage> message);

    public abstract boolean postProcessMessage(Message<IMessage> message);
}

后来我订阅了以下频道

channelProcessor = (IChannelProcessor) obj;
                        serviceActivatorHandler = new ServiceActivatingHandler(channelProcessor, "handleMessage");
                        String processorChannelName = config.get(processName, Constants.PARAMETER_KEY_CHANNEL);
                        utils.createInputChannel(processorChannelName).subscribe(serviceActivatorHandler);

是说okey或服务激活程序应该将消息转发到另一个端点以采取措施。

第二个问题是,我正在尝试创建通道的多个使用者(线程),并指出我需要确保消息仅被处理一次。

我发现除了taskExecutor以外的其他派遣人员都可以实现这一点,如何在Java中以编程方式实现类似的事情

<int:channel id="receiverChannel">
       <int:dispatcher task-executor="workerThreadExecutor"/>
</int:channel>
<task:executor id="workerThreadExecutor" pool-size="15" queue-capacity="10"  rejection-policy="DISCARD" />
<int:service-activator id="worker" ref="workerThread" method="process" input-channel="receiverChannel" />
<bean id="workerThread" class="com.uppi.poc.throttler.WorkerThread" />

0 个答案:

没有答案