spring-cloud-stream-samples icon indicating copy to clipboard operation
spring-cloud-stream-samples copied to clipboard

Using @Output to define a channel binds a default SendingHandler in addition to custom MessageHandlers (i.e. ExpressionEvaluatingRouter in this case)

Open ngbalk opened this issue 7 years ago • 3 comments

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

ngbalk avatar Jul 31 '18 15:07 ngbalk

Yes, this is the expected behavior. Maybe you could explain the use-case and we can help review it.

sabbyanandan avatar Oct 09 '18 16:10 sabbyanandan

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.

ngbalk avatar Oct 09 '18 20:10 ngbalk

@walliee This is the issue that we were seeing.

ngbalk avatar Apr 26 '19 17:04 ngbalk