集成有效负载路由器问题

时间:2018-09-17 14:57:05

标签: spring-integration

我正在尝试配置有效负载路由器以将消息路由到Rabbitmq,ibmq和kafka MOM。在某些情况下,有效负载将必须路由到多个MOM,这是代码

@ServiceActivator(inputChannel = "routerChannel", outputChannel = "outputChannel")
public PayloadTypeRouter router(Log message) {
    PayloadTypeRouter router = new PayloadTypeRouter();
    for (Platform platform : new MessageConfig().getConfig(message.getClientKey())) {
        System.out.println("platform type=" + platform.getRouter());
        if (platform.getRouter().equals(BridgeType.Bridge.rabbitmq.toString())) {
            router.setChannelMapping(String.class.getName(), "rabbitChannel");
        } else if (platform.getRouter().equals(BridgeType.Bridge.ibmmq.toString())) {
            router.setChannelMapping(String.class.getName(), "ibmmqChannel");
        } else if (platform.getRouter().equals(BridgeType.Bridge.kafka.toString())) {
            router.setChannelMapping(String.class.getName(), "kafkaChannel");
        }
    }
    return router;
}

之前我有下面的代码可以正常工作(发送给单个MOM,但不能同时发送给两个MOM)

@Router(inputChannel = "routerChannel")
public String route(Log message) {
    log.info("message in the router='{}'", message.getClientKey());
    for (Platform platform : new MessageConfig().getConfig(message.getClientKey())) {
        System.out.println("platform type=" + platform.getRouter());
        if (platform.getRouter().equals(BridgeType.Bridge.rabbitmq.toString())) {
            return "rabbitChannel";
        } else if (platform.getRouter().equals(BridgeType.Bridge.ibmmq.toString())) {
            return "ibmmqChannel";
        } else if (platform.getRouter().equals(BridgeType.Bridge.kafka.toString())) {
            return "kafkaChannel";
        }
    }
    return "errorChannel";
}

不确定我在做什么错,在这里感谢任何帮助

1 个答案:

答案 0 :(得分:1)

<罢工> <?xml version="1.0" encoding="UTF-8"?> <SourceDetails> <Origin>FEED</Origin> <Identifier>IR</Identifier> <Timestamp>2017-01-01T02:11:01Z</Timestamp> </SourceDetails> <AsOfDate>2017-01-02</AsOfDate> <Instrument> <CommonCode>GB0</CommonCode> </Instrument> <Rate>0.69</Rate> PayloadTypeRouter仅支持一个目的地。

如果要路由到多个目的地,请将MethodInvokingRouterRecipientListRouter一起使用Recipients

实际上,我错了。您只需从第二个示例中返回MessageSelector