서버 역할을 할 때 때때로 클라이언트 변환이 완료되면 채널을 닫아야 합니다. endpoint 옵션을 disconnect=true 로 설정하여 이 작업을 수행할 수 있습니다.
그러나 다음과 같이 Camel에 메시지별로 지시할 수도 있습니다. Camel에 채널을 종료하도록 지정하려면 CamelNettyCloseChannelWhenComplete 가 부울 true 값으로 설정된 헤더를 추가해야 합니다. 예를 들어, 아래 예제에서는 bye 메시지를 클라이언트에 다시 작성한 후 채널을 종료합니다.
from("netty4:tcp://localhost:8080").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
exchange.getOut().setBody("Bye " + body);
// some condition which determines if we should close
if (close) {
exchange.getOut().setHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, true);
}
}
});
from("netty4:tcp://localhost:8080").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
exchange.getOut().setBody("Bye " + body);
// some condition which determines if we should close
if (close) {
exchange.getOut().setHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, true);
}
}
});
Copy to ClipboardCopied!Toggle word wrapToggle overflow