Difference between Transformer and Invoke service

Hi All,
I am not able to figure out the difference between transformer and invoke Service.

Is there any other difference then:

  1. Transformer perform multiple value transformations in one go.

  2. Transformers are passed only a reference to their mapped inputs, whereas regular invokes (pub.flow:invoke) operate on the same pipeline object as the calling service.

I would appreciate any help on this.

Regards
Sachin

Hello,
With a service, you are invoking it either under a MAP step or not. So there are differences as follows:

  1. Under a MAP step, you can group a number of seemingly independent services together to conslidated view of a set of execution. These services DO NOT execute in parallel and the order of execution IS NOT guaranteed.

  2. The transformer style service passes a scoped version of the pipeline. The values that are added or removed from the inner service ppipeline will not be present after the transformer invoke. Modifications to passed in values will occur to only those that are referenced style (Lists, Tables, fields of Document, certain Object).

Good day.

Yemi Bedu

Hi Yemi,
Thanks for your valuable information. I have some more doubts regarding the same:
1.Is it true that information always passed by value in case of invoke service and by reference for transformer.
2.Whenever we invoke service, we can use previous pipeline information but it is not true in case when we call it by transformer. Is it true?

Thanks in advance.

Regards
Sachin

Hi Sachin,

I am not totally sure of the answer for your first question.

For the second one, as told by Yemi Bedu, the order of transformers execution is not guranteed. Hence, you can’t have the output of one transformer for another one. So, when you look at using multiple transformers in a single Map step, take into consideration only the values of pipeline variables before the Map step is being executed.

Hope I am clear to you.

Regards,
Hemanth

Another thing that I observed from Transformer vs Invoke Service :
by invoking pub.flow.debugLog via
→ Transformer in Map step : nothing is printed on server log.
→ Invoke Service step : message is printed on server log.

Anyone can explain the behaviour?

Thanks!

The way a service can be used as a transformer or invoke is like calling by reference and calling by value respectively.

Transformers run on a separate thread. Variables are created in a new pipeline and values of the variables are copied from the parent service pipeline to the new pipeline when using a Transformer. Copying of the data in and out of the service might make it slower when dealing with large data sets. Invoke uses the same thread as the parent service and references the variables that are already in the parent’s pipeline.

Because of the way pipeline is managed, transformers may be slow if a large data set is copied to the inputs and outputs of the service. When the data types are simple it may not make much difference in performance as with regard to a Transformer but when dealing with loops and large data invokes may be faster as copying of this data would require more resources.

The values or names of the variables in the transformers pipeline do not affect the parent pipeline. Where as in invokes any changes to the pipeline variables gets reflected in the parent pipeline. So naming of the variables in the pipeline becomes the developer’s responsibility when invoking the services. Any changes to the variables in the child service can affect values of the variables in the parent.

Any new variables in the service invoke pipeline would be reflected in the parent’s pipeline. So it becomes the developer’s responsibility in creating and dropping with the variables.

As soon as the transformer step is complete the thread is ready garbage collection. All the variables in the child service are ready for garbage collection. The developer need not worry too much about maintaining the pipeline when using as a transformer. This can help free the pipeline variables that are no longer required. Whereas in invoke it’s the direct opposite. Since invoke uses the same thread as the parent it would not drop any variables unless otherwise specified.

Error Handling
The difference in the way errors are handled in Invoke or a Transformer is similar in line with the way pipeline is handled. Transformer hides the data from the parent service other than the input and output variables. As soon as the thread is complete all variables and any errors generated are made available for garbage collection so if any error is thrown it is not available outside of that transformer. The error will not be passed on to the parent service unless the transformer has an output variable and references the errors inside the service to the output. Transformers can be made to pass the errors to the parent service in another way but the errors would be in the lastError/pipeline/lastError of the parent pipeline service. Hence, if there is no error handling inside of a service, using that service as a transformer is highly inadvisable. As a rule of thumb; Adapter Services and like wise should not be used as transformers. If any services from WmPublic are being used as transformers, data validation is necessary before passing inputs to the transformer which can throw an exception.

Invoke:
When using as an Invoke any error thrown puts lastError in the pipeline data. So when child service errors out the parent would have the error information.

5 Likes

Good summary ! by brijil.balachandran.

ty!

Ty brijil,

Still i have one confusion: can we use multiple writeToFile or replace services as transformers. i am using writeToFile service 4 time. Is that possible?

Hi Rohit,

you can have several transformers in one map step, but it is not deteministic in which order they will be evaluated.

Remember that transformers are only executed when there is at least one field from output mapped to the out pipeline of the step.

Regards,
Holger

1 Like

That was a very good explanation Balachandran. Thank you!