As alluded to in the overview, the MessageSource
interface is itself a marker
interface for any "source" of Messages. The two sub-interfaces - PollableSource
and SubscribableSource
- accommodate two types of source: those that must be
polled and those that send Messages on their own. An example of the first type would be a source that represents
a directory in the File-system, and an example of the second type would be an inbound RMI invocation.
The PollableSource interface defines a single method for receiving Message
objects.
public interface PollableSource<T> extends MessageSource<T> { Message<T> receive(); }
The BlockingSource
interface extends PollableSource
and adds a single method with a timeout:
Message<T> receive(long timeout);
Spring Integration also provides a MethodInvokingSource
implementation that serves as an
adapter for invoking any arbitrary method on a plain Object (i.e. there is no need to implement an interface).
To use the MethodInvokingSource
, provide the Object reference and the method name.
MethodInvokingSource source = new MethodInvokingSource(); source.setObject(new SourceObject()); source.setMethodName("sourceMethod"); Message<?> result = source.receive();
It is also possible to configure a MethodInvokingSource
in XML by providing a
bean reference in the "source" attribute of a <channel-adapter> element along with a "method" attribute.
<channel-adapter source="sourceObject" method="sourceMethod" channel="someChannel"/>