Reputation: 33
i am trying to configure payload router to route messages to either rabbitmq,ibmq and kafka MOM's. payload will have to be routed to more than one MOM in some cases, here is the code
@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;
}
earlier i had below code which was working fine(sending to individual MOM but not to two at same time)
@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";
}
not sure what i am doing wrong , appreciate any help here
Upvotes: 0
Views: 57
Reputation: 174664
PayloadTypeRouter
and MethodInvokingRouter
only support one destination.
Use a RecipientListRouter
with Recipients
with MessageSelector
s if you want to route to multiple destinations.
Actually, I was wrong; you can simply return List<String>
from your second example.
Upvotes: 1