Menu Close
12.5. Netty ランタイムの設定
概要
Netty ランタイムは、分離されたエンドポイントを使用する HTTP サービスプロバイダーと HTTP コンシューマーによって使用されます。ランタイムのスレッドプールを設定できます。また、Netty ランタイムを使用して HTTP サービスプロバイダーのセキュリティー設定を複数設定することもできます。
Maven 依存関係
Apache Maven をビルドシステムとして使用する場合は、プロジェクトの pom.xml
ファイルに以下の依存関係を追加し、Netty ランタイムのサーバー側の実装 (Web サービスエンドポイントを定義するため) をプロジェクトに追加できます。
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-netty-server</artifactId> <version>${cxf-version}</version> </dependency>
プロジェクトの pom.xml
ファイルに次の依存関係を含めることで、Netty ランタイムのクライアント側実装 (Web サービスクライアントの定義用) をプロジェクトに追加できます。
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-netty-client</artifactId> <version>${cxf-version}</version> </dependency>
namespace
Netty ランタイムの設定に使用される要素は、namespace http://cxf.apache.org/transports/http-netty-server/configuration で定義されます。通常、プレフィックス httpn
を使用して参照されます。Netty 設定要素を使用するには、例12.17「Netty ランタイム設定 namespace」 にある行をエンドポイント設定ファイルの beans
要素に追加する必要があります。また、設定要素の namespace を xsi:schemaLocation
属性に追加する必要があります。
例12.17 Netty ランタイム設定 namespace
<beans ... xmlns:httpn="http://cxf.apache.org/transports/http-netty-server/configuration" ... xsi:schemaLocation="... http://cxf.apache.org/transports/http-netty-server/configuration http://cxf.apache.org/schemas/configuration/http-netty-server.xsd ...">
engine-factory 要素
httpn:engine-factory
要素は、アプリケーションによって使用される Netty ランタイムの設定に使用されるルート要素です。この属性には単一の必須属性 bus
があり、その値は、設定されている Netty インスタンスを管理する Bus
の名前です。
値は通常、デフォルトの Bus
インスタンスの名前である cxf
です。
httpn:engine-factory
要素には、Netty ランタイムファクトリーによってインスタンス化された HTTP ポートの設定に使用される情報が含まれる 3 つの子があります。子は 表12.11「Netty ランタイムファクトリを設定するための要素」 に記載されています。
表12.11 Netty ランタイムファクトリを設定するための要素
要素 | 説明 |
---|---|
| 特定の Netty ランタイムインスタンスの設定を指定します。「engine 要素」 を参照してください。 |
HTTP サービスプロバイダーを保護するための再利用可能なプロパティーのセットを指定します。これには、プロパティーセットを参照できる一意な識別子を指定する単一の属性 | |
Netty インスタンスのスレッドプールを制御するための再利用可能なプロパティーセットを指定します。これには、プロパティーセットを参照できる一意な識別子を指定する単一の属性 「スレッドプールの設定」 を参照してください。 |
engine 要素
httpn:engine
要素は、Netty ランタイムの特定のインスタンスを設定するために使用されます。表12.12「Netty ランタイムインスタンスの設定するための属性」 は、httpn:engine
要素によってサポートされる属性を示しています。
表12.12 Netty ランタイムインスタンスの設定するための属性
属性 | 説明 |
---|---|
|
Netty HTTP サーバーインスタンスによって使用されるポートを指定します。port 属性に |
| Netty HTTP サーバーインスタンスによって使用されるリッスンアドレスを指定します。値は、ホスト名または IP アドレスになります。指定されていない場合、Netty HTTP サーバーはすべてのローカルアドレスをリッスンします。 |
| Netty コネクションの最大読み取りアイドル時間を指定します。このタイマーは、基盤になるストリームに読み取りアクションがあるときはいつでもリセットされます。 |
| Netty コネクションの最大書き込みアイドル時間を指定します。このタイマーは、基盤になるストリームに書き込みアクションがあるときはいつでもリセットされます。 |
| Netty コネクションの集約されたコンテンツの最大サイズを指定します。デフォルト値は 10MB です。 |
httpn:engine
要素には、セキュリティープロパティーを設定するための子要素が 1 つと、Netty インスタンスのスレッドプールを設定するための子要素が 1 つあります。各種類の設定に対して、設定情報を直接提供するか、親の httpn:engine-factory
要素で定義された設定プロパティーのセットへの参照を提供できます。
httpn:engine
のサポートされる子要素を、表12.13「Netty ランタイムインスタンスを設定するための要素」 に示します。
表12.13 Netty ランタイムインスタンスを設定するための要素
要素 | 説明 |
---|---|
特定の Netty インスタンスに使用されるセキュリティーを設定するためのプロパティーセットを指定します。 | |
| |
特定の Netty インスタンスによって使用されるスレッドプールのサイズを指定します。「スレッドプールの設定」 を参照してください。 | |
| |
|
|
|
|
スレッドプールの設定
Netty インスタンスのスレッドプールのサイズは、次のいずれかの方法で設定できます。
-
engine-factory
要素のidentifiedThreadingParameters
要素を使用してスレッドプールのサイズを指定します。その後、threadingParametersRef
要素を使用して要素を参照します。 -
threadingParameters
要素を使用して、スレッドプールのサイズを直接指定します。
threadingParameters
要素には、表12.14「Netty スレッドプールを設定するための属性」 に記載されているように、スレッドプールのサイズを指定する 1 つの属性があります。
httpn:identifiedThreadingParameters
要素には単一の子要素 threadingParameters
があります。
表12.14 Netty スレッドプールを設定するための属性
属性 | 説明 |
---|---|
| リクエストを処理するために Netty インスタンスが使用できるスレッドの数を指定します。 |
例
例12.18「Netty インスタンスの設定」 は、さまざまな Netty ポートを設定する設定フラグメントを示しています。
例12.18 Netty インスタンスの設定
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:h="http://cxf.apache.org/transports/http/configuration" xmlns:httpn="http://cxf.apache.org/transports/http-netty-server/configuration" xmlns:sec="http://cxf.apache.org/configuration/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/transports/http-netty-server/configuration http://cxf.apache.org/schemas/configuration/http-netty-server.xsd" > ... <httpn:engine-factory bus="cxf"> <httpn:identifiedTLSServerParameters id="sample1"> <httpn:tlsServerParameters jsseProvider="SUN" secureSocketProtocol="TLS"> <sec:clientAuthentication want="false" required="false"/> </httpn:tlsServerParameters> </httpn:identifiedTLSServerParameters> <httpn:identifiedThreadingParameters id="sampleThreading1"> <httpn:threadingParameters threadPoolSize="120"/> </httpn:identifiedThreadingParameters> <httpn:engine port="9000" readIdleTime="30000" writeIdleTime="90000"> <httpn:threadingParametersRef id="sampleThreading1"/> </httpn:engine> <httpn:engine port="0"> <httpn:threadingParameters threadPoolSize="400"/> </httpn:engine> <httpn:engine port="9001" readIdleTime="40000" maxChunkContentSize="10000"> <httpn:threadingParameters threadPoolSize="99" /> <httpn:sessionSupport>true</httpn:sessionSupport> </httpn:engine> <httpn:engine port="9002"> <httpn:tlsServerParameters> <sec:clientAuthentication want="true" required="true"/> </httpn:tlsServerParameters> </httpn:engine> <httpn:engine port="9003"> <httpn:tlsServerParametersRef id="sample1"/> </httpn:engine> </httpn:engine-factory> </beans>