21

What is the fundamental difference between inbound and outbound channel adapters?

Any examples would be very helpful.

I have reviewed the Spring docs and this "directional" distinction is not clear to me. I support an application that has an outbound-channel-adapter configured, but I find the behavior counter intuitive with the outbound label. This adapter gets an external file, then brings it in to the application where we parse the file and persist the data.

This is similar to this question, but I wanted to focus more generally on channel adapters, and hopefully get more feedback!

Thanks!

Community
  • 1
  • 1
The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80
  • Based on what you said it seems that your application uses an outbound gateway which is something different than a channel adapter. The gateway receives a message, does an outbound operation (which can also be retrieving a file) and returns a message. A channel adapter is only uni directional (no reply). – daniel.eichten May 01 '15 at 20:32
  • It uses a channel adapter. What did I say indicative of a gateway? I can correct my wording... You can see the configuration at this sibling question http://stackoverflow.com/q/29994253/2860319 – The Gilbert Arenas Dagger May 01 '15 at 20:43

2 Answers2

37

Channel adapters are for one-way integration (gateways are bidirectional).

Concretely, inbound adapters are at the beginning of a flow, outbound adapters terminate a flow. Flows are typically rendered (and conceptually thought of as flowing from left to right)...

inbound-c-a->someComponent->someOtherComponent->outbound-ca

(where -> represents a channel).

There are two types of inbound channel adapters:

  • MessageProducers
  • MessageSources

MessageProducers are termed "message-driven" i.e. they unilaterally produce messages in a completely asynchronous manner, as soon as they are started; examples are JMS message-driven adapter, TCP inbound channel adapter, IMAP Idle (mail) channel adapter, etc.

MessageSources on the other hand are polled - a poller with some trigger causes the framework to ask the source for a message; the trigger can be on a fixed rate, cron expression etc. Examples are the (S)FTP adapters, Mail inbound adapter (POP3. IMAP).

Examples of outbound adapters are Mail outbound adapter (SMTP).

Gateways are two-way (request/reply).

Inbound gateways are where some external system sends a request and Spring Integration replies.

Outbound gateways are where Spring Integration makes the request and some external system replies.

I hope that clears things up.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • if this is the case why for amqp there is an inbound and an outbound gateway? I'm struggling connecting a pojo as a gateway to amqp request/reply queues – Korgen May 15 '18 at 15:04
  • Yes; I suggest you ask a new question showing your code. – Gary Russell May 15 '18 at 15:07
  • @GaryRussell: _Gateways are two-way_ you said. Would a server in a simple echo service considered two-way? In another words, in my simple echo example https://stackoverflow.com/q/55154418/1185845 would you recommend to use Gateway on both client *and* server side? No adapters necessary? – Espinosa Mar 14 '19 at 13:02
  • Yes; anything request/reply is a gateway; you would use adapters for fire and forget or receive and send no reply, or you can have collaborating adapters for request/reply as discussed in the documentation. I answered your question with some sample code. – Gary Russell Mar 14 '19 at 13:40
6

in and out are relative directions, it must have a base. in spring integration, the base is the Spring integration framework ( that can be looked as a message bus), the adapters put message into it are in, the adapters take message out from it are out.

Andrew
  • 784
  • 9
  • 15