생산자 끝점이 'inputChannel'에 메시지를 보내고 소비자 끝점이 inputChannel에서 메시지를 읽고 ackChannel에 응답을 보내는 프로그램을 작성했습니다.
아래 코드 스니펫을 찾으세요.
@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);
}
}
소비자 엔드포인트
@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();
}
}
생산자 엔드포인트에 생성 메시지 방식을 사용하여 메시지를 보낼 때 소비자 'consumeMessage' 방식에 도달하지 않습니다. 여기에 누락된 것이 있습니까?
producerEndpoint.produceMessage("Hello World");
하지만 inputChannel에 직접 메시지를 보내면 consumerMessage 메소드로 수신하고, ReceiveAcknowledgement 메소드로 응답을 보낸다.
ProducerEndpoint를 아래와 같이 MessagingGateway로 모델링하면 모든 것이 잘 작동합니다.
@Component
@MessagingGateway(name = "myGateway", defaultRequestChannel = "inputChannel")
public interface ProducerEndpoint {
@Gateway(requestChannel = "inputChannel", replyTimeout = 2, requestTimeout = 200)
public void produceMessage(String message);
}
메서드를 직접 호출할 때 서비스 활성제가 outputchannel에 메시지를 보낼 수 없습니까?
Spring Integration 개념을 잘못 이해하신 것 같습니다.
@ServiceActivator
메서드를 직접 호출하는 것은 메시징과 관련하여 아무 것도 하지 않습니다.
엔드포인트에 메시지를 보내려면 게이트웨이 또는 다른 메시징 메커니즘을 사용해야 합니다.
임의의 메서드에 주석을 달아 메서드 호출 결과를 메시지로 게시할 수 있습니다@Publish
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다