242.8. 동일한 포트가 있는 여러 경로 사용
동일한 CamelContext에서 동일한 포트(예: io.netty.bootstrap.ServerBootstrap
인스턴스)를 공유하는 Netty4 HTTP에서 여러 경로를 사용할 수 있습니다. 이를 수행하려면 경로에서 동일한 io.netty.bootstrap.ServerBootstrap
인스턴스를 공유하므로 여러 부트스트랩 옵션이 경로에서 동일해야합니다. 인스턴스는 생성된 첫 번째 경로의 옵션을 사용하여 구성됩니다.
경로가 동일해야 하는 옵션은 org.apache.camel.component.netty4.NettyServerBootstrapConfiguration
구성 클래스에 정의된 모든 옵션입니다. 다른 옵션을 사용하여 다른 경로를 구성한 경우 Camel은 시작 시 예외를 발생시켜 옵션이 동일하지 않음을 나타냅니다. 이를 완화하려면 모든 옵션이 동일한지 확인합니다.
다음은 동일한 포트를 공유하는 두 개의 경로가 있는 예입니다.
동일한 포트를 공유하는 두 개의 경로
from("netty4-http:http://0.0.0.0:{{port}}/foo") .to("mock:foo") .transform().constant("Bye World"); from("netty4-http:http://0.0.0.0:{{port}}/bar") .to("mock:bar") .transform().constant("Bye Camel");
다음은 1st 경로로 동일한 org.apache.camel.component.netty4.NettyServerBootstrapConfiguration
옵션이 없는 잘못된 2nd 경로의 예입니다. 이로 인해 시작 시 Camel이 실패합니다.
동일한 포트를 공유하는 두 개의 경로이지만 두 번째 경로는 잘못 구성되었으며 시작 시 실패합니다.
from("netty4-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("netty4-http:http://0.0.0.0:{{port}}/bar?ssl=true") .to("mock:bar") .transform().constant("Bye Camel");
242.8.1. 여러 경로를 사용하여 동일한 서버 부트스트랩 구성 재사용
org.apache.camel.component.nettyServerBootstrapConfiguration 유형의 단일 인스턴스에 공통 서버 부트스트랩 옵션을 구성하면 Netty4
HTTP 소비자에서 bootstrapConfiguration
옵션을 사용하여 모든 소비자에서 동일한 옵션을 참조하고 재사용할 수 있습니다.
<bean id="nettyHttpBootstrapOptions" class="org.apache.camel.component.netty4.NettyServerBootstrapConfiguration"> <property name="backlog" value="200"/> <property name="connectionTimeout" value="20000"/> <property name="workerCount" value="16"/> </bean>
그리고 경로에서는 아래와 같이 이 옵션을 참조합니다.
<route> <from uri="netty4-http:http://0.0.0.0:{{port}}/foo?bootstrapConfiguration=#nettyHttpBootstrapOptions"/> ... </route> <route> <from uri="netty4-http:http://0.0.0.0:{{port}}/bar?bootstrapConfiguration=#nettyHttpBootstrapOptions"/> ... </route> <route> <from uri="netty4-http:http://0.0.0.0:{{port}}/beer?bootstrapConfiguration=#nettyHttpBootstrapOptions"/> ... </route>