Using @Output to define a channel binds a default SendingHandler in addition to custom MessageHandlers (i.e. ExpressionEvaluatingRouter in this case)
I'm very interested in doing dynamic destination binding with Kafka as a binder. I've pulled down this project and made slight modification. Instead of creating a channel with:
@Bean(name = "sourceChannel")
public MessageChannel localChannel() {
return new DirectChannel();
}
https://github.com/spring-cloud/spring-cloud-stream-samples/blob/e927b01bec4c15b422259150ddeae87e6385b0bd/source-samples/dynamic-destination-source/src/main/java/demo/SourceWithDynamicDestination.java#L74
I am doing
interface TestSource {
@Output("sourceChannel")
MessageChannel sourceChannel();
}
When I do the latter, I notice that 2 MessageHandlers are registered to the UnicastingDispatcher:
- our ExpressionEvaluatingRouter
- SendingHandler
This becomes a problem because using the RoundRobinLoadBalancingStrategy, only every other message hits the ExpressionEvaluatingRouter.
I'm wondering if this is expected behavior or perhaps a misuse of the @Output annotation?
Nick
Yes, this is the expected behavior. Maybe you could explain the use-case and we can help review it.
I would expect that when I define a Router, it takes precedent over any other Handler... whereas right now I'm seeing that due to the RoundRobinLoadBalancingStrategy, using my custom Router to handle a message is effectively useless as only every-other message is handled by my Router.
The use case is that I want to route my messages over "multi-tenant" topics (a topic prefixed with some tenantId like $tenantId$_topicName) by using a custom TenantRouter, but with the current behavior, only every-other message is handled by my TenantRouter.
@walliee This is the issue that we were seeing.