简体   繁体   中英

How do I connect to a Db2 Event Store database from a Python program?

I am trying to connect to a Db2 Event Store database version 2.0 from a python program and I am having trouble with the SSL configuration. In version 1.1.3 I used to set ConfigurationReader.setSSLEnabled(True) and that was enough for me to connect, how do I do the same in version 2.0 ?

I haven't have extensive experience with EventStore1.1.3 tho. But In EventStore 2.0, you will need to provide several other configurations.

EventStore has the detaild guide on the environment setup for remote applications here

https://www.ibm.com/support/knowledgecenter/SSGNPV_2.0.0/develop/dev-guide.html

But I will summarize it for you. You will need to setup following steps:

1/ Download the spark 2.2.1 or 2.3.2, and then set up SPARK_HOME shell env var.

export  SPARK_HOME=<SPARK_DIR>

2/ Download the EventStore java client jar ibm-db2-eventstore-client-nnnjar which is open sourced on Maven. Move the jar to the spark jars directory

mv <ibm-db2-eventstore-client-n.n.n.jar> $SPARK_HOME/jars

3/ Download the EventStore Python package, and export the package path

export PYTHONPATH="${PYTHONPATH}:<Python_package_location>

4/ Prepare for the Java keystore that contains the db2 EventStore server issued public certificate. You will need the keystore and its password.

  • If the EventStore server is using the default SSL certificate, then you can get the keystore file and it's password using REST API. See https://www.ibm.com/support/knowledgecenter/SSGNPV_2.0.0/local/REST_API_keystore.html .
  • If the administratore has provided EventStore server with their own certificate, please ask the administratore for the keystore and public certificate. In the following code snippit, eventstore connection will be configured.

  • userid: EventStore user's username .

  • password: EventStore user's password .
  • keystore_path: Absolute path to the java keystore file containing public certificate .
  • keystore_pwd: keystore file's password .

from eventstore.common import ConfigurationReader
​
ConfigurationReader.setConnectionEndpoints("<JDBC_CONNECTION_ENDPOINT>;<SCALA_CONNECTION_ENDPOINT>")

ConfigurationReader.setEventUser("<userid>")

ConfigurationReader.setEventPassword("<password>")
​
ConfigurationReader.setSslKeyStoreLocation("<keystore_path>")
ConfigurationReader.setSslKeyStorePassword("<keystore_pwd>")

ConfigurationReader.setSslTrustStoreLocation("<keystore_path>")

ConfigurationReader.setSslTrustStorePassword("<keystore_pwd>")

ConfigurationReader.setClientPluginName("IBMIAMauth")

ConfigurationReader.setClientPlugin(True)

ConfigurationReader.setSSLEnabled(True)

With above configurations, you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM