241.8. 동일한 포트에서 여러 경로 사용
동일한 CamelContext에서 동일한 포트(예: org.jboss.netty.bootstrap.ServerBootstrap 인스턴스)를 공유하는 Netty HTTP 의 경로가 여러 개 있을 수 있습니다. 이 작업을 수행하려면 경로에서 동일한 org.jboss.netty.bootstrap.ServerBootstrap 인스턴스를 공유하므로 경로에서 동일한 부트스트랩 옵션이 동일해야 합니다. 인스턴스는 생성된 첫 번째 경로의 옵션으로 구성됩니다.
경로가 동일해야 하는 옵션은 org.apache.camel.component.netty.NettyServerBootstrapConfiguration 구성 클래스에 정의된 모든 옵션입니다. 다른 옵션을 사용하여 다른 경로를 구성한 경우 Camel은 시작 시 옵션이 동일하지 않음을 나타내는 예외가 발생합니다. 이를 완화하기 위해 모든 옵션이 동일합니다.
다음은 동일한 포트를 공유하는 두 경로가 있는 예입니다.
동일한 포트를 공유하는 두 경로
from("netty-http:http://0.0.0.0:{{port}}/foo")
.to("mock:foo")
.transform().constant("Bye World");
from("netty-http:http://0.0.0.0:{{port}}/bar")
.to("mock:bar")
.transform().constant("Bye Camel");
그리고 여기에 동일한 org.apache.camel.component.netty.NettyServerBootstrapConfiguration 옵션이 첫 번째 경로로 잘못 구성되어 있지 않은 2차 경로의 예는 다음과 같습니다. 이로 인해 시작 시 Camel이 실패합니다.
동일한 포트를 공유하는 두 개의 경로이지만 두 번째 경로가 잘못 구성되어 시작에 실패합니다.
from("netty-http:http://0.0.0.0:{{port}}/foo")
.to("mock:foo")
.transform().constant("Bye World");
// we cannot have a 2nd route on same port with SSL enabled, when the 1st route is NOT
from("netty-http:http://0.0.0.0:{{port}}/bar?ssl=true")
.to("mock:bar")
.transform().constant("Bye Camel");
241.8.1. 여러 경로를 사용하여 동일한 서버 부트스트랩 구성 재사용 링크 복사링크가 클립보드에 복사되었습니다!
org.apache.camel.component.netty.NettyServerBootstrapConfiguration 유형의 단일 인스턴스에 공통 서버 부트스트랩 옵션을 구성하면 Netty HTTP 소비자에서 bootstrapConfiguration 옵션을 사용하여 모든 소비자에서 동일한 옵션을 참조하고 재사용할 수 있습니다.
<bean id="nettyHttpBootstrapOptions" class="org.apache.camel.component.netty.NettyServerBootstrapConfiguration">
<property name="backlog" value="200"/>
<property name="connectTimeout" value="20000"/>
<property name="workerCount" value="16"/>
</bean>
그리고 경로에서는 아래 표시된 대로 이 옵션을 참조하십시오.
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/foo?bootstrapConfiguration=#nettyHttpBootstrapOptions"/>
...
</route>
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/bar?bootstrapConfiguration=#nettyHttpBootstrapOptions"/>
...
</route>
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/beer?bootstrapConfiguration=#nettyHttpBootstrapOptions"/>
...
</route>
241.8.2. OSGi 컨테이너의 여러 번들에서 여러 경로로 동일한 서버 부트스트랩 구성 재사용 링크 복사링크가 클립보드에 복사되었습니다!
자세한 내용과 이 작업을 수행하는 방법에 대한 예제는 Netty HTTP Server 예제를 참조하십시오.