The Message Bus plays a central role, but its configuration is quite simple since it is primarily concerned with managing internal details based on the configuration of channels and endpoints. The bus is aware of its host application context, and therefore is also capable of auto-detecting the channels and endpoints. The Message Bus can be configured with a single empty element:
<message-bus/>
The Message Bus provides default error handling for its components in the form of a configurable error channel, and it will first check for a channel bean named 'errorChannel' within the context:
<message-bus/> <channel id="errorChannel" capacity="500"/>
When exceptions occur in a scheduled poller task's execution, those exceptions will be wrapped in
ErrorMessages
and sent to the 'errorChannel' by default. To enable global error
handling, simply register a handler on that channel. For example, you can configure Spring Integration's
ErrorMessageExceptionTypeRouter
as the handler of an endpoint that is subscribed to the
'errorChannel'. That router can then spread the error messages across multiple channels based on
Exception
type. However, since most of the errors will already have been wrapped in
MessageDeliveryException
or MessageHandlingException
,
the ErrorMessageExceptionTypeRouter
is typically a better option.
The 'message-bus' element accepts several more optional attributes. First, you can control whether the
MessageBus
will be started automatically (the default) or will require explicit startup
by invoking its start()
method (MessageBus
implements
Spring's Lifecycle
interface):
<message-bus auto-startup="false"/>
Another configurable property is the reference to a TaskScheduler
implementation.
If not provided, a default will be created. The scheduler is responsible for managing the pollers.
<message-bus task-scheduler="someScheduler"/>
When the endpoints are concurrency-enabled with their own 'taskExecutor' reference, the invocation of the handling methods will happen within that executor's thread pool and not the main scheduler pool. However, when no task-executor is provided for an endpoint's poller, then it will be invoked in the dispatcher's thread (with the exception of subscribable channels where the subscribers may be invoked directly).