3 複数のデータベースに対するOracle REST Data Servicesの構成
Oracle REST Data Servicesでは、複数のデータベースに接続する機能がサポートされています。この項では、リクエストを適切なデータベースにルーティングするための異なる戦略を説明します。
リクエストURLについて
Oracle REST Data Servicesは、リクエストを適切なデータベースにルーティングするための多数の異なる戦略をサポートしています。これらの戦略はすべて、リクエストURLを調べ、URLのどこかの一致に基づいてデータベースを選択することを利用しています。それは、リクエストURLの関連する部分をまとめるのに役立ちます。次のURLについて考えます。
https://www.example.com/ords/sales/f?p=1:1
このURLは、次のセクションで構成されています。
-
プロトコル:
https
-
ホスト名:
www.example.com
-
コンテキスト・ルート:
/ords
コンテキスト・ルートは、アプリケーション・サーバー上のOracle REST Data Servicesがデプロイされている場所です。
-
リクエスト・パス:
/sales/f?p=1.1
これは、リクエストURLのコンテキスト・ルートからの相対となる部分です。
異なるアプリケーションに対しては、リクエスト・パス内の特定の接頭辞またはリクエストURL全体の特定の接頭辞に基づいてリクエストをルーティングすることが重要です。
複数データベースを構成するには、次の2つのステップを行います。
-
データベース接続情報の構成
-
どのリクエストをどのデータベースにルーティングするかの構成
追加のデータベースの構成
最初にOracle REST Data Servicesを構成するとき、default
という名前のデフォルトのデータベース接続を構成します。install
コマンドを使用して追加のデータベース接続を作成できます。
ヒント:
install
コマンドの完全なヘルプを表示するには、次のように入力します。
ords install --help
ords --config <configuration folder> install
Oracle REST Data Services - Interactive Install
Enter a number to select the type of installation
[1] Install or upgrade ORDS in the database only
[2] Create or update a database pool and install/upgrade ORDS in the database
[3] Create or update a database pool only
Choose [1]:
オプション2を選択します
Enter a number to select the database pool to update, or create an additional database pool.
The selected (or created) database pool will be used to install or upgrade ORDS in the database.
[1] default jdbc:oracle:thin:@//localhost:1521/orcl
[2] Create an additional database pool
Choose [1]:
オプション2を選択します
Enter the database pool name:
db2と入力します
これが新しいプールのマッピング・パターンになります。デフォルト・プールの初回設定と同様に、引き続きプロンプトに応答します。
拡張ルーティング
ノート:
カスタム・マッピングが構成されている場合、データベース・プール名を使用したデフォルト・マッピングは有効になっていません。関連項目:
追加のデータベースの構成リクエスト・パスに基づくルーティング
- ファイル
<ords_config_folder>/databases/<database_name>/paths
を開くか作成します - このデータベースによって提供されるパスを入力します。
pathsファイルの場所の例
ords_conf/
+-- databases/
| +-- db1/
| | +-- wallet/
| | +-- paths
| | +-- pool.xml
| +-- db2/
| +-- wallet/
| +-- paths
| +-- pool.xml
+-- globals/
ords_conf/databases/db1/paths
sales
ords_conf/databases/db2/pathsords_conf/databases/db2/paths
support
/finance/department1
前述のルールは、次のすべてのリクエストと一致します。
http://example.com/ords/sales --> db1
http://example.com/ords/sales/leads --> db1
https://www.example.com/ords/sales/forecasting.report?month=jan --> db1 (If www.example.com resolves to the same system as example.com.)
http://example.com/ords/support --> db2
http://example.com/ords/finance/department1 --> db2
リクエスト・ホスト名に基づくルーティング
hostnamesファイルを使用して、ホスト名に基づいたリクエスト・ルーティング・ルールを作成できます。これを行うには、次のステップを実行します:
- ファイル
<ords_config_folder>/databases/<database_name>/hostnames
を開くか作成します。 - このデータベースによって提供されるホスト名を追加します。
ords_conf/
+-- databases/
| +-- db1/
| | +-- wallet/
| | +-- hostnames
| | +-- pool.xml
| +-- db2/
| +-- wallet/
| +-- hostnames
| +-- pool.xml
+-- globals/
例: ords_conf/databases/db1/hostnames
www.example.com
example.org
ords_conf/databases/db2/hostnames
foo.bar.com
前述のルールは、次のようにリクエストを対応するデータベース接続に一致させます。
http://www.example.com/ords/ --> db1
http://example.org:8080/ords/f?p=1:1 --> db1
https://foo.bar.com/ords/myschema/resource --> db2
前述のルールは、次のリクエストに一致しません。
http://example.com/ords/ (The hostname is missing the www.)
http://foo.bar.net/ords/myschema/resource --> db2 (hostname is different