240.8. 동일한 포트로 여러 경로 사용
동일한 CamelContext에 동일한 포트(예: org.jboss.netty.bootstrap.ServerBootstrap 인스턴스)를 공유하는 Netty HTTP 의 여러 경로가 있을 수 있습니다. 이렇게 하려면 경로에서 동일한 org.jboss.netty.bootstrap.ServerBootstrap 인스턴스를 공유하므로 여러 부트스트랩 옵션이 동일해야 합니다. 인스턴스는 생성된 첫 번째 경로의 옵션으로 구성됩니다.
경로가 동일해야 하는 옵션은 org.apache.camel.component.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");
다음은 1st 경로와 동일한 org.apache.camel.component.netty.NettyServerBootstrapConfiguration 옵션이 없는 잘못된 2nd 경로의 예입니다. 이로 인해 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");
240.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>
240.8.2. OSGi 컨테이너의 여러 번들에 있는 여러 경로에서 동일한 서버 부트스트랩 구성 재사용 링크 복사링크가 클립보드에 복사되었습니다!
Netty HTTP Server 예제를 참조하십시오. 자세한 내용은 Netty HTTP Server 예제를 참조하십시오.