Configuring Connections to External Data Stores
You can define reusable connections to external data stores in your members' configuration files or with the Java member API. When you have a configured connection, you can then use it in the Pipeline API, SQL mappings, and MapStores.
Quickstart Configuration
To configure a connection to the external data store, you must provide a unique identifier for the connection as well as a factory that creates the connection.
This example configuration defines connections to both a MySQL database and a H2 data store.
<hazelcast>
<external-data-store name="my-mysql-database">
<class-name>com.hazelcast.datastore.JdbcDataStoreFactory</class-name>
<properties>
<property name="jdbcUrl">jdbc:mysql://mysql.example.org:3306</property>
<property name="username">my_user</property>
<property name="password">my_password</property>
</properties>
<shared>true</shared>
</external-data-store>
<external-data-store name="my-other-database">
<class-name>com.hazelcast.datastore.JdbcDataStoreFactory</class-name>
<properties>
<property name="jdbcUrl">jdbc:h2:mem:my-other-database</property>
</properties>
<shared>true</shared>
</external-data-store>
</hazelcast>
hazelcast:
external-data-store:
my-mysql-database:
class-name: com.hazelcast.datastore.JdbcDataStoreFactory
properties:
jdbcUrl: jdbc:mysql://mysql.example.org:3306
username: my_user
password: my_password
shared: true
my-other-database:
class-name: com.hazelcast.datastore.JdbcDataStoreFactory
properties:
jdbcUrl: jdbc:h2:mem:my-other-database
shared: true
config
.addExternalDataStoreConfig(
new ExternalDataStoreConfig("my-mysql-database")
.setClassName(JdbcDataStoreFactory.class.getName())
.setProperty("jdbcUrl", "jdbc:mysql://mysql.example.org:3306")
.setProperty("username", "my_user")
.setProperty("password", "my_password")
.setShared(true)
)
.addExternalDataStoreConfig(
new ExternalDataStoreConfig("my-other-database")
.setClassName(JdbcDataStoreFactory.class.getName())
.setProperty("jdbcUrl", "jdbc:h2:mem:my-other-database")
.setShared(true)
);
Configuration Options for External Data Stores
The external data store has the following configuration options:
If you are using Java to configure the Mapstore, use the ExternalDataStoreConfig
object.
Option | Description |
---|---|
Default |
Example |
|
The unique identifier for the external data store. |
|
The name of a |
|
Any configuration properties that the factory in the |
|
Whether the factory in the |
Pre-Built Factories
Hazelcast comes with the following pre-built factories that you can configure in the class-name
configuration:
Factory | Description | Properties |
---|---|---|
|
Connect to a data store that supports JDBC. Supported data stores include MySQL, PostgreSQL, and H2. |
For available configuration properties see HikariCP configuration. This implementation is based on HikariDataSource. All properties are passed directly to |
If there are more JDBC connections used on a single member from a single job, they will share the same data store and connection pool.
If you use the slim distribution of Hazelcast with a built-in data store factory, make sure that you have an appropriate driver on your cluster’s classpath. |
Related Resources
You can also add new external data stores dynamically at runtime, see dynamic configuration.
Next Steps
Use your configured connection:
-
Build a data pipeline with the Pipeline API.
-
Query your data store, using a SQL mapping.
-
Build a cache with a MapStore.