Jetty の接続プールから Customer.io のデータ に接続
CData JDBC Driver for Customer.io は、Java Web アプリケーションへの統合が簡単です。この記事では、接続プールを設定することで Jetty から Customer.io のデータ に効率的に接続する方法を説明します。Jetty で Customer.io 用の JNDI リソースを設定していきましょう。
Customer.io 用の JDBC Driver を JNDI データソースとして設定
以下のステップで Jetty から Customer.io に接続します。
Jetty ベースで JNDI モジュールを有効にします。次のコマンドは、コマンドラインから JNDI を有効にします。
java -jar ../start.jar --add-to-startd=jndi- インストールディレクトリの lib サブフォルダにある CData およびライセンスファイルを、コンテキストパスの lib サブフォルダに追加します。
-
リソースとそのスコープを宣言します。リソース宣言に必要な接続プロパティを入力します。次の例では、WEB-INF\jetty-env.xml に Web アプリレベルで Customer.io データソースを宣言しています。
<Configure id='customeriodemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="customeriodemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="customeriodemo"/></Arg> <Arg>jdbc/customeriodb</Arg> <Arg> <New class="cdata.jdbc.api.APIDriver"> <Set name="url">jdbc:api:</Set> <Set name="Profile">C:\profiles\CustomerIO.apip</Set> <Set name="AuthScheme">APIKey</Set> <Set name="ProfileSettings">"APIKey</Set> </New> </Arg> </New> </Configure>API キー認証の設定
Customer.io App API Key を取得するには、Customer.io の UI で Data & Integrations > Integrations > Customer.io API に移動して、API キーを生成します。
以下の接続プロパティを設定してください:
- AuthScheme:APIKey に設定します。
- APIKey:Customer.io App API Key に設定します。
接続文字列の例
Profile=C:\profiles\CustomerIO.apip;AuthScheme=APIKey;ProfileSettings="APIKey=your_api_key";
-
Web.xml でリソースを設定します。
jdbc/customeriodb javax.sql.DataSource Container -
これで、java:comp/env/jdbc/customeriodb をルックアップして Customer.io にアクセスできます。
InitialContext ctx = new InitialContext(); DataSource mycustomerio = (DataSource)ctx.lookup("java:comp/env/jdbc/customeriodb");
Jetty 統合の詳細
上記のステップでは、シンプルな接続プールのシナリオでドライバーを設定する方法を説明しました。その他のユースケースや詳細については、Jetty ドキュメントのWorking with Jetty JNDI の章を参照してください。