Reputation: 159
I wish to understand what does serviceactivator annotation do? Because I want to modify message when I got it through serviceactivator. For example I have seen, there is no message parameter I can control. Why handle can receive message, even I cannot see any message parameter passed in, what is the principle?
@Bean
@ServiceActivator(inputChannel="requests")
public MessageHandler jmsMessageHandler((ActiveMQConnectionFactory connectionFactory) {
JmsSendingMessageHandler handler = new JmsSendingMessageHandler(new
JmsTemplate(connectionFactory));
handler.setDestinationName("requests");
return handler;
}
I wish I can do
@Bean
@ServiceActivator(inputChannel="requests")
public MessageHandler jmsMessageHandler(Message message) {
String new_message = message.split();
}
Upvotes: 0
Views: 4813
Reputation: 121442
The @ServiceActivator
wraps a call to the consumer endpoint. In case of MessageHandler
it is used as is and the message from the inputChannel
is passed to it. But if your code is not based on the MessageHandler
, but is a simple POJO method invocation, then everything is based on the signature of your method. In the end that POJO method call is wrapped to the MethodInvokingMessageHandler
.
In your case it must be something like this:
@ServiceActivator(inputChannel="requests", outputChannel="toJms")
public String jmsMessageHandler(Message message) {
return message.split();
}
So, no @Bean
, because we deal only with POJO method invocation. The message
is something incoming from request message and return String
is going to become a payload
from output message to processed somewhere downstream on the toJms
channel.
See more info in the Reference Manual: https://docs.spring.io/spring-integration/docs/current/reference/html/#annotations
Upvotes: 3