第11章 管理データソースの Data Grid Server への追加
管理データソースを Data Grid Server 設定に追加して、JDBC データベース接続の接続プールとパフォーマンスを最適化します。
11.1. マネージドデータソースの設定 リンクのコピーリンクがクリップボードにコピーされました!
Data Grid Server 設定の一部としてマネージドデータソースを作成し、JDBC データベース接続の接続プールとパフォーマンスを最適化します。その後、キャッシュ内のマネージドデータソースの JDNI 名を指定して、デプロイメントの JDBC 接続設定を一元化できます。
前提条件
データベースドライバーを、Data Grid Server インストールの
server/libディレクトリーにコピーします。ヒントData Grid コマンドラインインターフェイス (CLI) で
installコマンドを使用して、必要なドライバーをserver/libディレクトリーにダウンロードします。以下に例を示します。install org.postgresql:postgresql:42.4.3
手順
- Data Grid Server 設定を開いて編集します。
-
data-sourcesセクションに新しいdata-sourceを追加します。 -
name属性またはフィールドでデータソースを一意に識別します。 jndi-name属性またはフィールドを使用してデータソースの JNDI 名を指定します。ヒントJNDI 名を使用して、JDBC キャッシュストア設定でデータソースを指定します。
-
trueをstatistics属性またはフィールドの値に設定し、/metricsエンドポイント経由でデータソースの統計を有効にします。 connection-factoryセクションのデータソースへの接続方法を定義する JDBC ドライバーの詳細を提供します。-
driver属性またはフィールドを使用して、データベースドライバーの名前を指定します。 -
url属性またはフィールドを使用して、JDBC 接続 URL を指定します。 -
usernameおよびpassword属性またはフィールドを使用して、認証情報を指定します。 - 必要に応じて他の設定を指定します。
-
-
Data Grid Server ノードが接続をプールして再利用する方法を、
connection-poolセクションの接続プール調整プロパティーで定義します。 - 変更を設定に保存します。
検証
以下のように、Data Grid コマンドラインインターフェイス (CLI) を使用して、データソース接続をテストします。
CLI セッションを開始します。
bin/cli.shすべてのデータソースをリスト表示し、作成したデータソースが利用できることを確認します。
server datasource lsデータソース接続をテストします。
server datasource test my-datasource
マネージドデータソースの設定
XML
<server xmlns="urn:infinispan:server:15.0">
<data-sources>
<!-- Defines a unique name for the datasource and JNDI name that you
reference in JDBC cache store configuration.
Enables statistics for the datasource, if required. -->
<data-source name="ds"
jndi-name="jdbc/postgres"
statistics="true">
<!-- Specifies the JDBC driver that creates connections. -->
<connection-factory driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/postgres"
username="postgres"
password="changeme">
<!-- Sets optional JDBC driver-specific connection properties. -->
<connection-property name="name">value</connection-property>
</connection-factory>
<!-- Defines connection pool tuning properties. -->
<connection-pool initial-size="1"
max-size="10"
min-size="3"
background-validation="1000"
idle-removal="1"
blocking-timeout="1000"
leak-detection="10000"/>
</data-source>
</data-sources>
</server>
JSON
{
"server": {
"data-sources": [{
"name": "ds",
"jndi-name": "jdbc/postgres",
"statistics": true,
"connection-factory": {
"driver": "org.postgresql.Driver",
"url": "jdbc:postgresql://localhost:5432/postgres",
"username": "postgres",
"password": "changeme",
"connection-properties": {
"name": "value"
}
},
"connection-pool": {
"initial-size": 1,
"max-size": 10,
"min-size": 3,
"background-validation": 1000,
"idle-removal": 1,
"blocking-timeout": 1000,
"leak-detection": 10000
}
}]
}
}
YAML
server:
dataSources:
- name: ds
jndiName: 'jdbc/postgres'
statistics: true
connectionFactory:
driver: "org.postgresql.Driver"
url: "jdbc:postgresql://localhost:5432/postgres"
username: "postgres"
password: "changeme"
connectionProperties:
name: value
connectionPool:
initialSize: 1
maxSize: 10
minSize: 3
backgroundValidation: 1000
idleRemoval: 1
blockingTimeout: 1000
leakDetection: 10000