1

I am learning spring integration reading/watching a different stuff but I can't understand what service activator is.

I understood that there are two types of integration:
chanel and gateways. chanel is unidirectional integration but gateways is request/reply model. Gateways can be inbound(our system gets request and sends response) and outbound (our system sends request and receives response)

When I read about gateways I often see termin "service activator"

Could you clarify what does it mean ?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • See Enterprise Integration Patterns description: [Service Activator](https://www.enterpriseintegrationpatterns.com/patterns/messaging/MessagingAdapter.html) – Jesper Aug 28 '19 at 08:36

2 Answers2

3

The outbound gateway is essentially a particular case for a service activator abstraction for request/reply scenarios. Another case is an outbound channel adapter, which is a one-way, but still can be treated as a service activator because when we send a message to its inputChannel, we are going to call some code - which we can treat as a service. Therefore activating it.

A general component service activator exists there for all the use-cases which are not covered by particular implementation. Let's imaging you need to call some REST service. Right, you can use an HTTP Outbound Gateway with some specific options. Or you can write some custom code which uses a RestTemplate to call that service. you wrap your code into a service activator configuration and you end up with the same behavior for the whole integration solution.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    So service activator is a way of binding spring integration infrastructure and our custom code. Is it correct ? – gstackoverflow Aug 23 '19 at 15:21
  • Yes. That's correct. Although the same happens with gateways, but as I said they are just service activator implementations for particular cases. – Artem Bilan Aug 23 '19 at 15:28
0

A service activator is a call to a method in a bean.

<service-activator ref="myService" method="aMethod"/>

will call

@Service
public class MyService {
    public A aMethod(@Header(value = "param1") String param){
        //code
    }
}

@Header annotation allows to use an existing value in the header. That is an example.

You can also use it like this:

<service-activator expression="@myService.aMethod('My param')"/>
Mannekenpix
  • 744
  • 7
  • 15