Why testOutputHandler() doesn't print anything? It seems that alarmHandler() doesn't push message to outputChannel = "testOutput"
@Bean
@ServiceActivator(inputChannel = CHANNEL_ALARM, requiresReply = "true", outputChannel = "testOutput")
public MessageHandler alarmHandler(SessionFactory<FTPFile> sessionFactory) {
return message -> {
System.out.println(CHANNEL_ALARM);
System.out.println(message.getHeaders());
};
}
@Bean
@ServiceActivator(inputChannel = "testOutput" )
public MessageHandler testOutputHandler() {
return message -> {
System.out.println("test");
System.out.println(message.getHeaders());
};
}
Here is console output, we can see that alarmHandler does its work, but testOutput doesn't
2022-10-04 17:56:53.710 INFO 26092 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] alarm {file_remoteHostPort=192.168.1.44:21, file_remoteFileInfo={"directory":false,"filename":"Alarm_Logs_12.9.2022_0.41.csv","link":false,"modified":1664782140000,"permissions":"----------","remoteDirectory":"for_it","size":88804}, file_remoteDirectory=for_it, channel=alarm, id=67d21ff6-e0ef-1992-2b32-ab759a8c1076, closeableResource=org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession@4b9ffb22, file_remoteFile=Alarm_Logs_12.9.2022_0.41.csv, timestamp=1664884618273}
CodePudding user response:
The MessageHandler
you use in your alarmHandler()
bean definition has a contract like this:
void handleMessage(Message<?> message) throws MessagingException;
Indeed it does not produce anything to the outputChannel
since its return type is void
.
Not sure what is your expectations since you definitely placed yourself to that corner.
Top make it send to the testOutput
you must change your method signature like this, for example:
@ServiceActivator(inputChannel = CHANNEL_ALARM, requiresReply = "true", outputChannel = "testOutput")
public Strung alarmHandler(Message<?> message) {
System.out.println(CHANNEL_ALARM);
System.out.println(message.getHeaders());
return "foo";
}