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