public class UnicastingDispatcher extends AbstractDispatcher
MessageDispatcher
that will attempt to send a
Message
to at most one of its handlers. The handlers will be tried
as determined by the LoadBalancingStrategy
if one is configured. As
soon as one of the handlers accepts the Message, the dispatcher will
return true
and ignore the rest of its handlers.
If the dispatcher has no handlers, a MessageDispatchingException
will be
thrown. If all handlers throw Exceptions, the dispatcher will throw an
AggregateMessageDeliveryException
.
A load-balancing strategy may be provided to this class to control the order in which the handlers will be tried.
logger
Constructor and Description |
---|
UnicastingDispatcher() |
UnicastingDispatcher(Executor executor) |
Modifier and Type | Method and Description |
---|---|
boolean |
dispatch(Message<?> message)
Dispatch the message.
|
void |
setFailover(boolean failover)
Specify whether this dispatcher should failover when a single
MessageHandler throws an Exception. |
void |
setLoadBalancingStrategy(LoadBalancingStrategy loadBalancingStrategy)
Provide a
LoadBalancingStrategy for this dispatcher. |
void |
setMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator) |
addHandler, getHandlerCount, getHandlers, removeHandler, setMaxSubscribers, toString, tryOptimizedDispatch
public void setFailover(boolean failover)
MessageHandler
throws an Exception. The default value is
true
.failover
- The failover boolean.public void setLoadBalancingStrategy(@Nullable LoadBalancingStrategy loadBalancingStrategy)
LoadBalancingStrategy
for this dispatcher.loadBalancingStrategy
- The load balancing strategy implementation.public void setMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator)
public final boolean dispatch(Message<?> message)
MessageDispatcher
message
- the message.