Announcement Announcement Module
Collapse
No announcement yet.
Difference between service-activator and outbound-channel-adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between service-activator and outbound-channel-adapter

    I have several places in my application where I want a Spring bean to receive a message and perform some action (say, persist the message to the database via myBatis).

    So far, I've been using an outbound-channel-adapter tag to reference an inner bean with a method. I see that I could use a service-activator instead, but I cannot tell what the advantage of one over the other is. The service adapter documentation seems to be more on point, but the OCA seems to do what I want: "Defines a Channel Adapter that receives from a MessageChannel and passes to a method-invoking MessageHandler."

    Is there any reason to favor one over the other?

  • #2
    It's primarily an issue of semantics. If the component always represents a "terminal" endpoint, then I would stick with outbound-channel-adapter. The service-activator is usually used where a service is invoked with the content of a "request" Message and will most likely return a result value as a "reply" Message. However, another angle might be thinking of the outbound-channel-adapter as something that plays a more "infrastructural" role (passing on to some other system, just logging, etc.) while the service-activator should be used when the component being invoked really is playing the role of a business-level service in your application.

    Hopefully that gives you a few ideas.
    -Mark

    Comment


    • #3
      Jason

      The simple explanation is this. If you want to invoke a *void* method on a bean, then you can use OCA or SA.

      However, if you have non-void methods on the bean this means that your endpoint will not only receive a Message but will alos produce a Message which has to go somewhere and Service Activator allows you to define output-channel as well as input-channel.

      The bottom line is that adapters (both inbound and outbound) are unidirectional. The inbound generally implies the start of the flow and the outbound the end of the flow. And then there are gateway which is a whole other subject.

      Having said that, service-activators are more configurable especially with SI 2.0 release where you can now benefit from Spring Expression Language allowing you to include a simple computation logic withut pointing to any bean, so even in the *void* situation you may still want to use service-activator:
      Code:
      <int:service-activator input-channel="myChannel" expression="payload.foo()"/>
      providing that the payload object has a void foo() method
      and
      Code:
      <int:service-activator input-channel="myChannel" output-channel="outChannel" expression="payload.toUpperCase()"/>
      providing that the payload object is a String, the output message will be the upper cased string

      Hope that helps

      Comment


      • #4
        Thanks, guys. I appreciate the thorough answers.

        Comment

        Working...
        X