Custom Spring Scope not working for Message Channe

2019-07-04 21:53发布

In spring integration, I am trying to create a Direct Message channel with a custom scope as follows

  ...
  <int:channel id="myChannel" scope="validCustomScope" />
  <int:service-activator ref="validSericeReference_WithSameValidCustomScope" method="handleMessage" input-channel="myChannel"/>
  ...

However, I am running into an exception ..

org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel 

Note: this custom scope works for other beans. This issue is similar to what is discussed here, but to no resolution. If someone can help resolve this issue, it will be a huge help.

2条回答
We Are One
2楼-- · 2019-07-04 22:04

The service activator will only get subscribed to one of the instances. The others will throw Dispatcher has no subscribers.

Your custom scope would need to figure out how to propagate the subscription (service activator's MessageHandler) for every instance when the service activator is start() ed, and then propagate it to any new instances created after the endpoint was started.

Non-trivial probably.

That said. the benefit of a scoped channel sending messages to a non-scoped service is not clear to me.

Perhaps if you explain what you are trying to do with the custom scope there might be a general solution, but my guess it will need some tricky code in the custom scope.

查看更多
Summer. ? 凉城
3楼-- · 2019-07-04 22:05

That is a good explanation to why "Dispatcher has no subscribers" exception is encountered. We are going to employ Spring Integration in a multi-tenant environment so each tenant uses his/her own channels and service activators. We have applied the same scope to the service activator bean definition. Any suggestions to this?

<bean id="validSericeReference" class="ValidSericeClass" scope="validCustomScope"/> 
查看更多
登录 后发表回答