A newer version of Platform is available.

View latest

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.

  • XML

  • YAML

  • Java

<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.

Table 1. External data store configuration options
Option Description

Default

Example

name (required)

The unique identifier for the external data store.

class-name (required)

The name of a com.hazelcast.datastore.ExternalDataStoreFactory implementation that creates instances of an external data store connection.

properties

Any configuration properties that the factory in the class-name configuration expects to receive.

shared

Whether the factory in the class-name configuration returns reusable connections for use in different MapStores, jobs, and SQL mappings. The behaviour of this configuration depends on the implementation of the factory. The default value is true.

Pre-Built Factories

Hazelcast comes with the following pre-built factories that you can configure in the class-name configuration:

Table 2. Factories
Factory Description Properties

com.hazelcast.datastore.JdbcDataStoreFactory

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 HikariConfig.

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.

You can also add new external data stores dynamically at runtime, see dynamic configuration.

Next Steps

Use your configured connection: