Configuring Data Connections to External Systems
A data connection contains the metadata that Hazelcast needs to connect an external system. You can define a data connection in your members' configuration files, in the Java member API, or in SQL, and reuse the same connection details in the Pipeline API, SQL mappings, and MapStores.
Quickstart Configuration
To configure a data connection to an external system, you must do the following:
- Provide a unique identifier (
name) for the data connection. - Choose the correct type of data connection for your external system.
See examples for other connection properties for each data connection type.
Example JDBC Data Connection
This example configuration shows a data connection to a MySQL database using a JDBC connection.
- XML
- YAML
- Java
- SQL
<hazelcast>
<data-connection name="my-mysql-database">
<type>JDBC</type>
<properties>
<property name="jdbcUrl">jdbc:mysql://mysql.example.org:3306</property> (1)
<property name="user">my_user</property> (2)
<property name="password">my_password</property>
</properties>
<shared>true</shared>
</data-connection>
</hazelcast>
hazelcast:
data-connection:
my-mysql-database:
type: JDBC
properties:
jdbcUrl: jdbc:mysql://mysql.example.org:3306 (1)
user: my_user (2)
password: my_password
shared: true
config
.addDataConnectionConfig(
new DataConnectionConfig("my-mysql-database")
.setType("JDBC")
.setProperty("jdbcUrl", "jdbc:mysql://mysql.example.org:3306") (1)
.setProperty("user", "my_user") (2)
.setProperty("password", "my_password")
.setShared(true)
);
Data connections created in SQL behave differently to those defined in members' configuration files or in Java.
- To retain SQL-defined data connections after a cluster restart, you must enable SQL metadata persistence. This feature is available in the Enterprise Edition.
- You can create or drop a data connection using SQL commands. To update a data connection, you need to drop and then recreate it.
CREATE DATA CONNECTION my_mysql_database
TYPE JDBC
SHARED
OPTIONS (
'jdbcUrl'='jdbc:mysql://mysql.example.org:3306', (1)
'user'='my_user', (2)
'password'='my_password');
For shared connections, the following optional properties allow you to control how the JDBC connection pool behaves. All other properties are passed directly to the JDBC driver.
Default values are in milliseconds except for where indicated.
| Property | Default Value | Description |
|---|---|---|
connection | 30000 (30 seconds) | Maximum time that Hazelcast waits for a connection from the pool when attempting to connect to the external system, typically a database. A SQL exception is thrown when the connection is exceeded before a connection becomes available. |
idle | 600000 (10 minutes) | Maximum time that the JDBC connection component allows a connection to sit idle in the connection pool. After the
|
keepalive | 0 (Disabled) | How frequently the JDBC connection component attempts to keep an idle connection alive. When the keepalive is reached, the idle connection is removed from the connection pool, pinged, and then returned to the pool. The minimum allowed keepalive value is 30000 ms (30 seconds), but a value in the range of minutes is recommended. |
max | 1800000 (30 minutes) | Maximum lifetime of a connection in the pool. Only closed connections are removed. A value of
|
minimum | Same as maximum | Minimum number of idle connections that the JDBC connection component attempts to maintain in the connection pool. When the number of idle connections dips below the
|
maximum | 10 (connections) | Maximum size of the connection pool, which includes both idle and active connections. The maximum sets the maximum number of connections to the external system. When the pool reaches this size, and no more idle connections are available, calls to get a new connection are blocked for up to the connection before timing out. |
Example Kafka Data Connection
This example shows the configuration of a data connection to a single Kafka broker.
- XML
- YAML
- Java
- SQL
<hazelcast>
<data-connection name="my-kafka">
<type>Kafka</type>
<properties>
<property name="bootstrap.servers">127.0.0.1:9092</property> (1)
<property name="key.deserializer">org.apache.kafka.common.serialization.IntegerDeserializer</property> (2)
<property name="key.serializer">org.apache.kafka.common.serialization.IntegerSerializer</property>
<property name="value.serializer">org.apache.kafka.common.serialization.StringSerializer</property>
<property name="value.deserializer">org.apache.kafka.common.serialization.StringDeserializer</property>
<property name="auto.offset.reset">earliest</property> (3)
</properties>
<shared>true</shared>
</data-connection>
</hazelcast>
hazelcast:
data-connection:
my-kafka:
type: Kafka
properties:
bootstrap.servers: 127.0.0.1:9092 (1)
key.deserializer: org.apache.kafka.common.serialization.IntegerDeserialize (2)
key.serializer: org.apache.kafka.common.serialization.IntegerSerializer
value.serializer: org.apache.kafka.common.serialization.StringSerializer
auto.offset.reset: earliest (3)
shared: true
config
.addDataConnectionConfig(
new DataConnectionConfig("my-kafka")
.setType("Kafka")
.setProperty("bootstrap.servers", "127.0.0.1:9092") (1)
.setProperty("key.deserializer", "org.apache.kafka.common.serialization.IntegerDeserialize") (2)
.setProperty("key.serializer", "org.apache.kafka.common.serialization.IntegerSerializer")
.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
.setProperty("auto.offset.reset", "earliest") (3)
.setShared(true)
);
Data connections created in SQL behave differently to those defined in members' configuration files or in Java.
- To retain SQL-defined data connections after a cluster restart, you must enable SQL metadata persistence. This feature is available in the Enterprise Edition.
- You can create or drop a data connection using SQL commands. To update a data connection, you need to drop and then recreate it.
CREATE DATA CONNECTION my_kafka
TYPE Kafka
SHARED
OPTIONS (
'bootstrap.servers'='127.0.0.1:9092', (1)
'key.deserializer'='org.apache.kafka.common.serialization.IntegerDeserialize', (2)
'key.serializer'='org.apache.kafka.common.serialization.IntegerSerializer',
'value.serializer'='org.apache.kafka.common.serialization.StringSerializer',
'auto.offset.reset'='earliest'); (3)
Example MongoDB Data Connection
This example configuration shows data connections to two MongoDB databases.
As in the example, you can supply authentication credentials to a MongoDB instance as part of the connection string, or separately.
- XML
- YAML
- Java
- SQL
<hazelcast>
<data-connection name="my-mongodb">
<type>Mongo</type>
<properties>
<property name="connectionString">mongodb://my_user:my_password@some-host:27017</property> (1)
<property name="database">my_database</property> (2)
</properties>
<shared>true</shared>
</data-connection>
<data-connection name="my-other-mongodb">
<type>Mongo</type>
<properties>
<property name="host">some_host</property> (3)
<property name="username">my_user</property> (4)
<property name="password">my_password</property>
<property name="database">my_other_database</property> (2)
</properties>
<shared>true</shared>
</data-connection>
</hazelcast>
hazelcast:
data-connection:
my-mongodb:
type: Mongo
properties:
connectionString: mongodb://my_user:my_password@some-host:27017 (1)
database: my_database (2)
shared: true
my-other-mongodb:
type: Mongo
properties:
host: some_host (3)
username: my_user (4)
password: my_password
database: my_other_database (2)
shared: true
config
.addDataConnectionConfig(
new DataConnectionConfig("my-mongodb")
.setType("Mongo")
.setProperty("connectionString", "mongodb://my_user:my_password@some-host:27017") (1)
.setProperty("database", "my_database") (2)
.setShared(true)
)
.addDataConnectionConfig(
new DataConnectionConfig("my-other-mongo")
.setType("Mongo")
.setProperty("host", "some-host") (3)
.setProperty("username", "my_user") (4)
.setProperty("password", "my_password")
.setProperty("database", "my_other_database") (2)
.setShared(true)
);
Data connections created in SQL behave differently from those defined in members' configuration files or in Java.
- To retain SQL-defined data connections after a cluster restart, you must enable SQL metadata persistence. This feature is available in the Enterprise Edition.
- You can create or drop a data connection using SQL commands. To update a data connection, you need to drop and then recreate it.
CREATE DATA CONNECTION my_mongodb
TYPE Mongo
SHARED
OPTIONS (
'connectionString'='mongodb://my_user:my_password@some-host:27017', (1)
'database'='my_database'); (2)
CREATE DATA CONNECTION my_mongodb
TYPE Mongo
SHARED
OPTIONS (
'host'='some-host', (1)
'username'='my_user', (2)
'password'='my_password'
'database'='my_other_database');
| Property | Default value | Description | When to use |
|---|---|---|---|
connection | The connection string used to connect to given MongoDB instance. More in Mongo documentation. | Can be omitted if you prefer to provide host, | |
database | Name of the database that can be accessed via this connection. If omitted, user will have access to all databases available to given Mongo user. | If you want to restrict usage of this Data Connection to a particular database. Mandatory if you want to use this Data Connection with GenericMapStore. | |
username | Username used to authenticate to Mongo. | If you want to avoid putting credentials in connection string, you can use this dedicated option. | |
password | Password used to authenticate to Mongo. | If you want to avoid putting credentials in connection string, you can use this dedicated option. | |
auth | admin | Authentication database - the database that holds user's data. It is not the same as the database option, both options can specify other databases - one to authenticate, other to actually read. | If you want to use username and password options, the auth option is the way to configure authentication database name (which can be contained in connection). |
host | Host to which Hazelcast will connect. Exclusive with connection. | If you want to use username and password options, the host option is the way to configure host name. | |
connection | 10 | Sets the minimum size of MongoClient's internal connection pool. | If you want to control connection pool size |
connection | 10 | Sets the maximum size of MongoClient's internal connection pool. | If you want to control connection pool size |
enable | Enables SSL support for Mongo client. Default value is false. | ||
invalid | Allows invalid hostnames in SSL. Default value is false. See Mongo docs for more info. | ||
key | Location of the key store, file must be present on all members. | ||
key | Type of the used key store. Defaults to system default. | ||
key | Password to the key store. | ||
trust | Location of the trust store, file must be present on all members. | ||
trust | Type of the used trust store. Defaults to system default. | ||
trust | Password to the trust store. |
Example Apache Pulsar Data Connection
- XML
- YAML
- Java
- SQL
<hazelcast>
<data-connection name="my-pulsar">
<type>Pulsar</type>
<properties>
<property name="brokerUrl">pulsar://pulsar.mydomain.com:6650</property> (1)
<property name="httpServiceUrl">http://pulsar.mydomain.com:8080</property> (2)
</properties>
<shared>true</shared>
</data-connection>
<data-connection name="my-other-pulsar">
<type>Pulsar</type>
<properties>
<property name="brokerUrl">pulsar://pulsar.mydomain.com:6650</property> (1)
<property name="httpServiceUrl">http://pulsar.mydomain.com:8080</property> (2)
<property name="tenant">myTenant</property> (3)
<property name="namespace">myNamespace</property> (3)
<property name="enableTransactions">true</property> (4)
</properties>
<shared>true</shared>
</data-connection>
</hazelcast>
listResources).hazelcast:
data-connection:
my-pulsar:
type: Pulsar
properties:
brokerUrl: pulsar://pulsar.mydomain.com:6650 (1)
httpServiceUrl: http://pulsar.mydomain.com:8080 (2)
shared: true
my-other-pulsar:
type: Pulsar
properties:
brokerUrl: pulsar://pulsar.mydomain.com:6650 (1)
httpServiceUrl: http://pulsar.mydomain.com:8080 (2)
tenant: myTenant (3)
namespace: myNamespace (3)
enableTransactions: true (4)
shared: true
config
.addDataConnectionConfig(
new DataConnectionConfig("my-pulsar")
.setType("Pulsar")
.setProperty("brokerUrl", "pulsar://pulsar.mydomain.com:6650") (1)
.setProperty("httpServiceUrl", "http://pulsar.mydomain.com:8080") (2)
.setShared(true)
)
.addDataConnectionConfig(
new DataConnectionConfig("my-other-pulsar")
.setType("Pulsar")
.setProperty("brokerUrl", "pulsar://pulsar.mydomain.com:6650") (1)
.setProperty("httpServiceUrl", "http://pulsar.mydomain.com:8080") (2)
.setProperty("tenant", "myTenant") (3)
.setProperty("namespace", "myNamespace") (3)
.setProperty("enableTransactions", "true") (4)
.setShared(true)
);
Data connections created in SQL behave differently from those defined in members' configuration files or in Java.
- To retain SQL-defined data connections after a cluster restart, you must enable SQL metadata persistence. This feature is available in the Enterprise Edition.
- You can create or drop a data connection using SQL commands. To update a data connection, you need to drop and then recreate it.
CREATE DATA CONNECTION my_pulsar
TYPE Pulsar
SHARED
OPTIONS (
'brokerUrl' = 'pulsar://pulsar.mydomain.com:6650' (1)
'httpServiceUrl' = 'http://pulsar.mydomain.com:8080 '(2)
)
CREATE DATA CONNECTION my_pulsar
TYPE Pulsar
SHARED
OPTIONS (
'brokerUrl' = 'pulsar://pulsar.mydomain.com:6650' (1)
'httpServiceUrl' = 'http://pulsar.mydomain.com:8080 '(2)
'tenant' = 'myTenant' (3)
'namespace' = 'myNamespace' (3)
'enableTransactions' = 'true' (4)
);
| Property | Default value | Description | When to use |
|---|---|---|---|
broker | Pulsar Broker URL, in a form of pulsar://myhost:port/ | Mandatory | |
http | URL of Pulsar's instance HTTP service, typically on port 8080. Example: http://myhost:8080/ | If you want to be able to list resources via Data Connections (not just treat like a connection pool). | |
tenant | If set, it limits which resources (topics) will be listed to only those of given tenant. | Only if you want to restrict access to subset of topics. | |
namespace | If set, it limits which resources (topics) will be listed to only those of given namespace. | Only if you want to restrict access to subset of topics. | |
enable | false | Enables transaction for returned Pulsar Clients. | If you want to use transactions with clients returned by this Data Connection. Must be set to true if used with Pulsar sink / SQL "INSERT INTO" Pulsar topic with EXACTLY_ processing guarantee. |
Example Hazelcast Data Connection
This example configuration shows a data connection to a remote Hazelcast cluster. You can use a Hazelcast data connection from the Pipeline API in Sources#remoteMapJournal source.
Currently, no SQL connector is available for Hazelcast data connections. This means that although you can create a data connection in SQL, you cannot yet use it in SQL, for example, in a mapping statement.
- XML
- YAML
- Java
- SQL
<hazelcast>
<data-connection name="my-remote-hazelcast">
<type>Hz</type>
<properties>
<property name="client_xml"> (1)
<![CDATA[ (2)
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
http://www.hazelcast.com/schema/client-config/hazelcast-client-config-6.0-SNAPSHOT.xsd">
<cluster-name>dev</cluster-name>
<network>
<cluster-members>
<address>172.17.0.2:5701</address>
</cluster-members>
</network>
</hazelcast-client>
]]>
</property>
</properties>
<shared>true</shared>
</data-connection>
</hazelcast>
client_xml, client_yml, client_xml_path, client_yml_path.client_xml_path property instead of using an embedded configuration file.hazelcast:
data-connection:
my-remote-hazelcast:
type: Hz
properties:
client_yml: | (1)
hazelcast-client: (2)
cluster-name: dev
network:
cluster-members:
- 172.17.0.2:5701
shared: true
client_xml, client_yml, client_xml_path, client_yml_path.client_yml_path property instead of using an embedded configuration file.config
.addDataConnectionConfig(
new DataConnectionConfig()
.setName("my-remote-hazelcast")
.setType("Hz")
.setProperty(
"client_xml", (1)
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + (2)
"<hazelcast-client xmlns=\"http://www.hazelcast.com/schema/client-config\"" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xsi:schemaLocation=\"http://www.hazelcast.com/schema/client-config" +
" http://www.hazelcast.com/schema/client-config/hazelcast-client-config-6.0-SNAPSHOT.xsd\">" +
" " +
" <cluster-name>dev</cluster-name>" +
" <network>" +
" <cluster-members>" +
" <address>172.17.0.2:5701</address>" +
" </cluster-members>" +
" </network>" +
"</hazelcast-client>")
.setShared(true)
);
client_xml, client_yml, client_xml_path, client_yml_path.client_xml_path or client_yml_path property instead of using an embedded configuration file.Data connections created in SQL behave differently to those defined in members' configuration files or in Java.
- To retain SQL-defined data connections after a cluster restart, you must enable SQL metadata persistence. This feature is available in the Enterprise Edition.
- You can create or drop a data connection using SQL commands. To update a data connection, you need to drop and then recreate it.
CREATE DATA CONNECTION "my-hazelcast-cluster"
TYPE Hz
SHARED
OPTIONS (
'client_xml'= (1)
'<?xml version="1.0" encoding="UTF-8"?> (2)
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
http://www.hazelcast.com/schema/client-config/hazelcast-client-config-6.0-SNAPSHOT.xsd">
<cluster-name>dev</cluster-name>
<network>
<cluster-members>
<address>172.17.0.2:5701</address>
</cluster-members>
</network>
</hazelcast-client>'
);
client_xml, client_yml, client_xml_path, client_yml_path.client_xml_path or client_yml_path property instead of using an embedded configuration file.Configuration Options for Data Connections
Data connections have the following configuration options.
If you are using Java to configure the Mapstore, use the DataConnectionConfig object.
| Option | Description |
|---|---|
| Default | Example |
name (required) | The unique identifier for the data connection. |
type (required) | The type of data connection required for your external system. The following types of connection are supported: JDBC, Kafka, Mongo, Hz (case-insensitive). |
properties | Any configuration properties that the data connection expects to receive. |
shared | Whether the data connection instance is reusable in different MapStores, jobs, and SQL mappings. This behavior depends on the implementation of the specific data connection. The default value is true. See the implementation of each data connection type for full details of reusability: KafkaDataConnection, MongoDataConnection, HazelcastDataConnection. |
You can use the EncryptionReplacer class to hide sensitive data in configuration files.
Types of Data Connection
The following types of data connection are available for use.
| Type | Description | Properties |
|---|---|---|
JDBC | Connect to external systems that support JDBC, including MySQL and PostgreSQL. | See example. If there is more than one JDBC connection used on a single member from a single job, they will share the same data store and connection pool. |
Kafka | Connect to a Kafka data source. | See example and Create a Kafka Mapping. |
Mongo | Connect to a MongoDB database. | See example. |
Hz | Connect to a remote Hazelcast cluster. | See example. |
If you use the slim distribution of Hazelcast with a built-in data connector, make sure that you have an appropriate driver on your cluster's classpath.
Next Steps
Use your configured connection:
- Build a data pipeline with the Pipeline API.
- Query your data connection, using a SQL mapping.
- Build a cache with a MapStore.