Spring Integration
  1. Spring Integration
  2. INT-2285

Provide Mechanism To Limit # Subscribers to a Channel

    Details

      Description

      One of the most common "gotchas" in the wild happens when a direct channel is unintentionally configured with multiple subscribers. This is likely a mistake in 99% of the cases, but for backwards compatibility, we need to retain the default round robin strategy. An easy solution is to provide a load balancing strategy, e.g.

      public class SingleSubscriberLoadBalancingStrategy implements LoadBalancingStrategy {
        public Iterator<MessageHandler> getHandlerIterator(Message<?> message, List<MessageHandler> handlers) {
          if (handlers.size() <= 1) {
      	return handlers.iterator();
          } 
          throw new MessageDeliveryException("Multiple subscribers are not supported.");
        }
      }
      

      along with namespace support:

      <channel id="direct">
         <dispatcher load-balancer="single-subscriber"/>
      </channel>
      

      Even better would be some way to make this a global default, e.g., make dispatcher a top level element:

      <dispatcher load-balancer="single-subscriber" default="true"/>
      

      or

      <dispatcher id="single" load-balancer="single-subscriber"/>
      
      <channel id="direct">
         <dispatcher ref="single"/>
      </channel>
      

        Activity

        Hide
        Gary Russell added a comment -

        Postponed the general concept of global configuration options to 3.0.

        To support this use case, we decided to use the ChannelInitializer to define the default load-balancing strategy which, by default, will continue to be Round Robin.

        Show
        Gary Russell added a comment - Postponed the general concept of global configuration options to 3.0. To support this use case, we decided to use the ChannelInitializer to define the default load-balancing strategy which, by default, will continue to be Round Robin.
        Show
        Gary Russell added a comment - PR: https://github.com/SpringSource/spring-integration/pull/543

          People

          • Assignee:
            Gary Russell
            Reporter:
            David Turanski
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1d
              1d
              Remaining:
              Remaining Estimate - 0d
              0d
              Logged:
              Time Spent - 1d
              1d