public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFactoryAware
false
(the
default), it will fail fast such that any Exception thrown by a MessageHandler may prevent subsequent handlers from
receiving the Message. However, when an Executor is provided, the Messages may be dispatched in separate Threads so
that other handlers are invoked even when the 'ignoreFailures' flag is false
.
If the 'ignoreFailures' flag is set to true
on the other hand, it will make a best effort to send the
message to each of its handlers. In other words, when 'ignoreFailures' is true
, if it fails to send to
any one handler, it will simply log a warn-level message but continue to send the Message to any other handlers.
logger
Constructor and Description |
---|
BroadcastingDispatcher() |
BroadcastingDispatcher(boolean requireSubscribers) |
BroadcastingDispatcher(Executor executor) |
BroadcastingDispatcher(Executor executor,
boolean requireSubscribers) |
Modifier and Type | Method and Description |
---|---|
boolean |
dispatch(Message<?> message) |
void |
setApplySequence(boolean applySequence)
Specify whether to apply sequence numbers to the messages prior to sending to the handlers.
|
void |
setBeanFactory(BeanFactory beanFactory) |
void |
setIgnoreFailures(boolean ignoreFailures)
Specify whether failures for one or more of the handlers should be ignored.
|
void |
setMinSubscribers(int minSubscribers)
If at least this number of subscribers receive the message,
dispatch(Message)
will return true. |
addHandler, getHandlerCount, getHandlers, removeHandler, setMaxSubscribers, toString, tryOptimizedDispatch, wrapExceptionIfNecessary
public BroadcastingDispatcher()
public BroadcastingDispatcher(Executor executor)
public BroadcastingDispatcher(boolean requireSubscribers)
public BroadcastingDispatcher(Executor executor, boolean requireSubscribers)
public void setIgnoreFailures(boolean ignoreFailures)
false
meaning that an Exception will be thrown when a handler fails. To override this and suppress Exceptions, set the
value to true
.
Keep in mind that when using an Executor, even without ignoring the failures, other handlers may be invoked after one throws an Exception. Since the Executor is most likely using a different thread, this flag would only affect whether an error Message is sent to the error channel or not in the case that such an Executor has been configured.
ignoreFailures
- true when failures are to be ignored.public void setApplySequence(boolean applySequence)
applySequence
- true when sequence information should be applied.public void setMinSubscribers(int minSubscribers)
dispatch(Message)
will return true. Default: 0.minSubscribers
- The minimum number of subscribers.public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory
in interface BeanFactoryAware
BeansException
public boolean dispatch(Message<?> message)
dispatch
in interface MessageDispatcher