228.7. 同じポートで複数のルートを使用する
同じ CamelContext では、同じポート( org.jboss.netty.bootstrap.ServerBootstrap
インスタンスなど)を共有する Netty HTTP の複数のルートを持つことができます。ルートが同じ org.jboss.netty.bootstrap.ServerBootstrap
インスタンスを共有するため、ルートに多くのブートストラップオプションが同じである必要があります。インスタンスは、最初に作成されたルートからのオプションを使用して設定します。
ルートが同一で設定されるオプションは、org.apache.camel.component.netty.NettyServerBootstrapConfiguration
設定クラスで定義されたすべてのオプションです。異なるオプションで別のルートを設定している場合、Camel は起動時に例外を発生させ、オプションが同一ではないことを示します。これを軽減するには、すべてのオプションが同一になるようにします。
以下は、同じポートを共有する 2 つのルートを使用した例です。
2 つのルートが同じポートを共有する
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");
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
オプションが 1st ルートと同じではない 2 番目のルートの例になります。これにより、起動時に Camel が失敗します。
同じポートを共有する 2 つのルートがありますが、2 番目のルートの設定が正しく設定され、起動時に失敗します。
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");
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");
228.7.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>
<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>
<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>