241.8. 사용자 정의 파이프라인
사용자 정의 채널 파이프라인은 Netty Endpoint URL에 지정할 필요 없이 사용자 정의 처리기(s), 인코더(s) 및 디코더(s)를 매우 간단한 방식으로 삽입하여 handler/interceptor 체인을 통해 사용자에게 완전한 제어를 제공합니다.
사용자 지정 파이프라인을 추가하려면 사용자 정의 채널 파이프라인 배당을 컨텍스트 레지스트리(JNDIRegistry 또는 camel-spring ApplicationContextRegistry 등)를 통해 생성 및 등록해야 합니다.
사용자 정의 파이프 라인 팩토리에는 다음과 같이 구성되어야 합니다.
-
Producer 연결 채널 파이프 라인 배당은 추상 클래스
ClientPipelineECDHEy를 확장해야합니다. -
소비자 연결 채널 파이프라인 배당은 추상 클래스
ServerECDHErECDHEy를 확장해야 합니다. -
클래스는 사용자 정의 처리기, 인코더 및 디코더를 삽입하기 위해 initChannel() 메서드를 재정의해야 합니다.
initChannel()메서드를 재정의하지 않으면 파이프라인에 연결된 핸들러, 인코더 또는 디코더 없이 파이프라인을 생성합니다.
아래 예는 ServerECDHErECDHEyley가 어떻게 생성될 수 있는지 보여줍니다.
241.8.1. 사용자 정의 파이프 라인 팩토리 사용 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
public class SampleServerInitializerFactory extends ServerInitializerFactory {
private int maxLineSize = 1024;
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
channelPipeline.addLast("encoder-SD", new StringEncoder(CharsetUtil.UTF_8));
channelPipeline.addLast("decoder-DELIM", new DelimiterBasedFrameDecoder(maxLineSize, true, Delimiters.lineDelimiter()));
channelPipeline.addLast("decoder-SD", new StringDecoder(CharsetUtil.UTF_8));
// here we add the default Camel ServerChannelHandler for the consumer, to allow Camel to route the message etc.
channelPipeline.addLast("handler", new ServerChannelHandler(consumer));
}
}
그런 다음 사용자 정의 채널 파이프 라인 팩토리를 레지스트리에 추가하고 다음과 같은 방식으로 comel 경로에 인스턴스화/사용할 수 있습니다.
Registry registry = camelContext.getRegistry();
ServerInitializerFactory factory = new TestServerInitializerFactory();
registry.bind("spf", factory);
context.addRoutes(new RouteBuilder() {
public void configure() {
String netty_ssl_endpoint =
"netty4:tcp://0.0.0.0:5150?serverInitializerFactory=#spf"
String return_string =
"When You Go Home, Tell Them Of Us And Say,"
+ "For Your Tomorrow, We Gave Our Today.";
from(netty_ssl_endpoint)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(return_string);
}
}
}
});