= Installing Debezium
include::_attributes.adoc[]
:toc:
:toc-placement: macro
:sectanchors:
:linkattrs:
:icons: font
:install-version: {debezium-version}
:install-dev-version: {debezium-dev-version}

There are several ways to install and use Debezium connectors, so we've documented a few of the most common ways to do this.

== Installing a Debezium Connector

If you've already installed https://zookeeper.apache.org[Zookeeper], http://kafka.apache.org/[Kafka], and http://kafka.apache.org/documentation.html#connect[Kafka Connect], then using one of Debezium's connectors is easy.
Simply download one or more connector plugin archives (see below), extract their files into your Kafka Connect environment, and add the parent directory of the extracted plugin(s) to https://docs.confluent.io/current/connect/userguide.html#installing-plugins[Kafka Connect's plugin path].
If not the case yet, specify the plugin path in your worker configuration (e.g. _connect-distributed.properties_) using the `plugin.path` property.
As an example, let's assume you have downloaded the Debezium MySQL connector archive and extracted its contents to _/kafka/connect/debezium-connector-mysql_.
Then you'd specify the following in the worker config:

[source]
----
plugin.path=/kafka/connect
----

Restart your Kafka Connect process to pick up the new JARs.

The connector plugins are available from Maven:

* https://repo1.maven.org/maven2/io/debezium/debezium-connector-mysql/{install-version}/debezium-connector-mysql-{install-version}-plugin.tar.gz[MySQL Connector plugin archive]
* https://repo1.maven.org/maven2/io/debezium/debezium-connector-postgres/{install-version}/debezium-connector-postgres-{install-version}-plugin.tar.gz[Postgres Connector plugin archive]
* https://repo1.maven.org/maven2/io/debezium/debezium-connector-mongodb/{install-version}/debezium-connector-mongodb-{install-version}-plugin.tar.gz[MongoDB Connector plugin archive]
* https://repo1.maven.org/maven2/io/debezium/debezium-connector-sqlserver/{install-version}/debezium-connector-sqlserver-{install-version}-plugin.tar.gz[SQL Server Connector plugin archive]
* https://repo1.maven.org/maven2/io/debezium/debezium-connector-oracle/{install-version}/debezium-connector-oracle-{install-version}-plugin.tar.gz[Oracle Connector plugin archive] (incubating)
* https://repo1.maven.org/maven2/io/debezium/debezium-connector-cassandra/{install-version}/debezium-connector-cassandra-{install-version}-plugin.tar.gz[Cassandra plugin archive] (incubating)

If immutable containers are your thing, then check out https://quay.io/organization/debezium[Debezium's container images] (https://hub.docker.com/r/debezium/[alternative source] on DockerHub) for Apache Kafka, Kafka Connect and Apache Zookeeper, with the different Debezium connectors already pre-installed and ready to go. Our xref:tutorial.adoc[tutorial] even walks you through using these images, and this is a great way to learn what Debezium is all about.
Of course you also can run Debezium on Kubernetes and xref:operations/openshift.adoc[OpenShift].

By default, the directory _/kafka/connect_ is used as plugin directory by the Debezium Docker image for Kafka Connect.
So any additional connectors you may wish to use should be added to that directory.
Alternatively, you can add further directories to the plugin path by specifying the `KAFKA_CONNECT_PLUGINS_DIR` environment variable when starting the container
(e.g. `-e KAFKA_CONNECT_PLUGINS_DIR=/kafka/connect/,/path/to/further/plugins`).
When using the Docker image for Kafka Connect provided by Confluent, you can specify the `CONNECT_PLUGIN_PATH` environment variable to achieve the same.

Not that Java 8 or later is required to run the Debezium connectors.

=== Consuming Snapshot Releases

Debezium executes nightly builds and deployments into the Sonatype snapshot repository.
If you want to try latest and fresh or verify a bug fix you are interested in, then use plugins from https://oss.sonatype.org/content/repositories/snapshots/io/debezium/[oss.sonatype.org].
The installation procedure is the same as for regular releases.

== Using a Debezium Connector

To use a connector to produce change events for a particular source server/cluster, simply create a configuration file for the
xref:connectors/mysql.adoc#deploying-a-connector[MySQL Connector],
xref:connectors/postgresql.adoc#deploying-a-connector[Postgres Connector],
xref:connectors/mongodb.adoc#deploying-a-connector[MongoDB Connector],
xref:connectors/sqlserver.adoc#deploying-a-connector[SQL Server Connector],
xref:connectors/oracle.adoc#deploying-a-connector[Oracle Connector]
or xref:connectors/cassandra.adoc#deploying-a-connector[Cassandra Connector]
and use the link:http://kafka.apache.org/documentation/#connect_rest[Kafka Connect REST API] to add that
connector configuration to your Kafka Connect cluster. When the connector starts, it will connect to the source and produce events
for each inserted, updated, and deleted row or document.

See the Debezium xref:connectors/index.adoc[Connectors] documentation for more information.

== Configuring Debezium Topics
Debezium uses (either via Kafka Connect or directly) multiple topics for storing data.
The topics have to be either created by an administrator or by Kafka itself by enabling auto-creation for topics.
There are certain limitations and recommendations which apply to topics:

* Database history topic (for the Debezium connectors for MySQL and SQL Server)
** Infinite (or very long) retention (no compaction!)
** Replication factor at least 3 for production
** Single partition
* Other topics
** Optionally, https://kafka.apache.org/documentation/#compaction[log compaction] enabled
(if you wish to only keep the _last_ change event for a given record);
in this case the `min.compaction.lag.ms` and `delete.retention.ms` topic-level settings in Apache Kafka should be configured,
so that consumers have enough time to receive all events and delete markers;
specifically, these values should be larger than the maximum downtime you anticipate for the sink connectors,
e.g. when updating them
** Replicated in production
** Single partition
*** You can relax the single partition rule but your application must handle out-of-order events for different rows in database (events for a single row are still totally ordered). If multiple partitions are used, Kafka will determine the partition by hashing the key by default. Other partition strategies require using SMTs to set the partition number for each record.

== Using the Debezium Libraries

Although Debezium is intended to be used as turnkey services, all of JARs and other artifacts are available in http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.debezium%22[Maven Central].

We do provide a small library so applications can xref:operations/embedded.adoc[embed any Kafka Connect connector] and consume data change events read directly from the source system. This provides a light weight system (since Zookeeper, Kafka, and Kafka Connect services are not needed), but as a consequence it is not as fault tolerant or reliable since the application must manage and maintain all state normally kept inside Kafka's distributed and replicated logs. It's perfect for use in tests, and with careful consideration it may be useful in some applications.
