【问题标题】:Overriding errorChannel configured in @MessagingGateway覆盖@MessagingGateway 中配置的errorChannel
【发布时间】:2018-11-09 15:15:15
【问题描述】:

我已将 @MessagingGateway 配置为使用错误通道,如下所示,该通道按预期工作。

@MessagingGateway(errorChannel = "DefaultInboundErrorHandlerChannel")
public interface InboundMessagingGateway {

    @Gateway(requestChannel = "InboundEntryChannel")
    void receive(XferRes response);

}

在流程中,我将对象传递给转换器,如下所示:

第 1 步:

@Transformer(inputChannel = "InboundEntryChannel", outputChannel = "TransmissionLogChannel")
public CassandraEntity createEntity(
        org.springframework.messaging.Message<XferRes> message) throws ParseException {
    XferRes response = message.getPayload();
    CassandraEntity entity = new CassandraEntity();
    // ... getters & setter ommitted for brevity
    return entity;
}

接下来,我将实体更新如下: 第 2 步:

@ServiceActivator(inputChannel = "TransmissionLogChannel", outputChannel="PublishChannel")
public XferRes updateCassandraEntity(
        org.springframework.messaging.Message<XferRes> message) {
    XferRes response = message.getPayload();
    this.cassandraServiceImpl.update(response);
    return response;
}

最后,我发布到一个 Kafka 主题,如下所示: 第 3 步:

@ServiceActivator(inputChannel = "PublishChannel")
public void publish(org.springframework.messaging.Message<XferRes> message){

        XferRes response = message.getPayload();
        publisher.post(response);       
    }

如果出现错误,我会将消息发布到发布错误对象以记录摄取的服务:

@ServiceActivator(inputChannel="defaultInboundErrorHandlerChannel")
public void handleInvalidRequest(org.springframework.messaging.Message<MessageHandlingException> message) throws ParseException {
    XferRes originalRequest = (XferRes) message.getPayload().getFailedMessage().getPayload();
    this.postToErrorBoard(originalRequest)
}

如果在Step 2:更新数据库时发生错误,那么我也想调用Step 3。一个简单的方法是删除 Step 2 并从 Step 1 调用更新数据库。

在 Spring Integration 中是否有任何其他方式我可以调用 Step 3 而不管是否发生错误。

【问题讨论】:

    标签: spring spring-integration integration


    【解决方案1】:

    这种技术称为PublishSubscribeChannel。由于我看到您在第二步中重用了有效负载以发送到第三步,因此它绝对是PublishSubscribeChannel 和两个顺序订阅者的用例。

    我的意思是你创建了一个PublishSubscribeChannel @Bean 并且那些@ServiceActivators 使用这个频道的名称。

    更多信息在Reference Manual。注意ignoreFailures属性:

    /**
     * Specify whether failures for one or more of the handlers should be
     * ignored. By default this is <code>false</code> meaning that an Exception
     * will be thrown whenever a handler fails. To override this and suppress
     * Exceptions, set the value to <code>true</code>.
     * @param ignoreFailures true if failures should be ignored.
     */
    public void setIgnoreFailures(boolean ignoreFailures) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-24
      • 2020-08-26
      • 2017-09-08
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      相关资源
      最近更新 更多