Reputation: 2152
I need to introduce processing step in spring integration something like that:
import org.springframework.messaging.Message;
public class SomeDocumentProcessingStep {
public Message<MyDocument> process(Message<MyDocument> myMessage) {
// do some manipulations with message like providing new headers;
return resultingMessage;
}
}
The question is how to include such processing step in spring integration configuration? I have something like that:
<int:chain input-channel="someInput" output-channel="someOutput">
<!--Here I want to use my processing step class -->
<!--Chain contains other processing steps like transformations -->
</int:chain>
One way on doing this if with service-activator
, but then I need to send new message manually from my service. Something like this:
public class SomeService {
private final MessageChannel outputChannel;
private final MessagingTemplate template;
// constructor ommited
public void distribute(Message<MyDocument> message) {
// do my manipulations
template.send(outputChannel, resultingMessage);
}
}
And configure it something like this:
<int:service-activator input-channel="someInput" ref="someService" method="distribute"/>
But I have a feeling that this is wrong approach. Is there a better way of doing that inside integration chain? I need this custom processing step that will be in the middle of processing of message. The usage of <int:header-enricher>
is not sufficient for me as it only provide a way of creating headers one by one. I want to do it in one class.
Upvotes: 1
Views: 200
Reputation: 121262
You go right way with the <service-activator>
inside chain
. Only the problem you are facing that you don’t need that channel on the service-activator
. It is a chain - a single composite endpoint for a set of steps. So, you still have to send message somehow into that someInput
, but that’s already will be an entry point for the whole chain. Please, read docs on the matter: https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/messaging-routing-chapter.html#chain
Upvotes: 2