首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >覆盖@MessagingGateway中配置的errorChannel

覆盖@MessagingGateway中配置的errorChannel
EN

Stack Overflow用户
提问于 2018-05-31 01:14:14
回答 1查看 432关注 0票数 1

我已经将@MessagingGateway配置为使用错误通道,其工作方式与预期一致。

代码语言:javascript
复制
@MessagingGateway(errorChannel = "DefaultInboundErrorHandlerChannel")
public interface InboundMessagingGateway {

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

}

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

第1步:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
@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主题,如下所示:Step 3:

代码语言:javascript
复制
@ServiceActivator(inputChannel = "PublishChannel")
public void publish(org.springframework.messaging.Message<XferRes> message){

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

在发生错误的情况下,我将消息发布到一个服务,该服务发布错误对象以记录摄取:

代码语言:javascript
复制
@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: in updating the DB时出现错误,那么我还想调用Step 3。一种简单的方法是删除步骤2 &从步骤1调用更新数据库。

在Spring Integration中有没有其他方法可以调用Step 3,而不管是否发生错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-31 04:00:33

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

我的意思是,您创建了一个PublishSubscribeChannel @Bean,而那些@ServiceActivator使用的是此通道的名称。

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

代码语言:javascript
复制
/**
 * 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) {
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50610217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档