Uploaded image for project: '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>
      

        Attachments

          Activity

            People

            • Assignee:
              grussell Gary Russell
              Reporter:
              dturanski 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