46.9. 사용자 정의 파이프라인


사용자 정의 채널 파이프라인은 매우 간단한 방법으로 Netty Endpoint URL에 지정하지 않고도 사용자 정의 처리기(s), 인코더 및 디코더를 삽입하여 처리기/차단 체인에 완전한 제어를 제공합니다.

사용자 지정 파이프라인을 추가하려면 컨텍스트 레지스트리(Registry 또는 camel-spring ApplicationContextRegistry 등)를 통해 컨텍스트로 사용자 정의 채널 파이프라인 팩토리를 생성하고 등록해야 합니다.

사용자 정의 파이프라인 팩토리는 다음과 같이 구성되어야 합니다.

  • Producer 연결 채널 파이프라인 팩토리에서 추상 클래스 ClientPipelineFactory 를 확장해야 합니다.
  • 소비자 연결 채널 파이프라인 팩토리에서 추상 클래스 Server>-<rFactory 를 확장해야 합니다.
  • 클래스는 사용자 정의 처리기, 인코더 및 디코더를 삽입하기 위해 initChannel() 메서드를 재정의해야 합니다. initChannel() 메서드를 재정의하지 않으면 파이프라인에 연결된 처리기, 인코더 또는 디코더 없이 파이프라인이 생성됩니다.

아래 예제에서는 Server>-<rFactory 팩토리를 만드는 방법을 보여줍니다.

46.9.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));
    }
}
Copy to Clipboard Toggle word wrap

그런 다음 사용자 정의 채널 파이프라인 팩토리를 레지스트리에 추가하고 다음과 같은 방식으로 camel 경로에서 인스턴스화/사용할 수 있습니다.

Registry registry = camelContext.getRegistry();
ServerInitializerFactory factory = new TestServerInitializerFactory();
registry.bind("spf", factory);
context.addRoutes(new RouteBuilder() {
  public void configure() {
      String netty_ssl_endpoint =
         "netty: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);
          }
       }
  }
});
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat