I written a program, where producer endpoint send messages to 'inputChannel' and consumer endpoint read the message from inputChannel and send the reply to ackChannel.
Find the below code snippet.
@Component
public class ProducerEndpoint {
@ServiceActivator(outputChannel = "inputChannel")
public Message<String> produceMessage(String message) {
return MessageBuilder.withPayload("Message Received").build();
}
@ServiceActivator(inputChannel = "ackChannel")
public void receiveAcknowledgement(String message) {
System.out.println("From Consumer : " + message);
}
}
Consumer ednpoint
@Component
public class ConsumerEndpoint {
@ServiceActivator(inputChannel = "inputChannel", outputChannel = "ackChannel", requiresReply="true")
public Message<String> consumeMessage(Message<String> message) {
System.out.println("From Producer : " + message);
return MessageBuilder.withPayload("Message Received").build();
}
}
When I send message to producer endpoint using produceMessage method, it is not reaching to consumer 'consumeMessage' method. Am I missing anything here?
producerEndpoint.produceMessage("Hello World");
But When I send the message directly to inputChannel, it is received by consumeMessage method and reply sent to receiveAcknowledgement method.
Things are working fine, when i modelled ProducerEndpoint as MessagingGateway like below.
@Component
@MessagingGateway(name = "myGateway", defaultRequestChannel = "inputChannel")
public interface ProducerEndpoint {
@Gateway(requestChannel = "inputChannel", replyTimeout = 2, requestTimeout = 200)
public void produceMessage(String message);
}
Can't a service activator send the message to outputchannel when i call the method directly?