= Tuning Apache Kafka
:description: Learn about default Kafka settings in OpenNMS {page-component-title} and how to change them to meet your system requirements, including multi-tenancy.

The configuration is shipped with some defaults, but depending on the size and network topology you might need to tune the Apache Kafka environment to meet certain needs.
Set Apache Kafka options directly in the `org.opennms.core.ipc.rpc.kafka.cfg` and `org.opennms.core.ipc.sink.kafka.cfg` file.

Alternatively, you can set Kafka producer/consumer options by defining additional system properties prefixed with `org.opennms.core.ipc.rpc.kafka` and `org.opennms.core.ipc.sink.kafka`.

Find available configuration parameters for Kafka here:

* link:https://kafka.apache.org/10/documentation.html#producerconfigs[Producer Configs] for RPC communication
* link:https://kafka.apache.org/10/documentation.html#newconsumerconfigs[New Consumer Configs] for Sink communication

== Multi-tenancy with {page-component-title} and Kafka

Topics will be automatically created and are prefixed by default with `OpenNMS`.
If you want to use an Apache Kafka cluster with multiple {page-component-title} instances, customize the topic prefix by setting the `org.opennms.instance.id` system property on {page-component-title} and all its Minions and Sentinels to a string value that identifies your instance.

.`$\{OPENNMS_HOME}/etc/opennms.properties.d/instance-id.properties`
[source, properties]
----
org.opennms.instance.id=MyNMS
----

Update the Minion's instance ID accordingly to match the {page-component-title} instance.

.`$\{MINION_HOME}/etc/custom.system.properties`.
[source, properties]
----
org.opennms.instance.id=MyNMS
----

== Tips for Kafka

* For Kafka RPC, the number of partitions must be greater than or equal to the number of Minions at a location, and should be a multiple of the number of Minions at a location.
When there are multiple locations, the partition count for RPC topics should be based on a multiple of the maximum number of Minions at the associated location.

* By default, Kafka RPC uses a buffer size of 900KB.
When set to a larger size, they will be split into 900kb chunks.
Configure the maximum buffer size by setting `org.opennms.core.ipc.rpc.kafka.max.buffer.size` to the desired size in bytes.

* Default time to live (time at which request will expire) is 20000ms (20 seconds).
To change it, configure the system property `org.opennms.core.ipc.rpc.kafka.ttl` in milliseconds.

== Disable single topic for Kafka RPC

By default, {page-component-title} uses single topic structure.
One request topic is created for each location and one response topic is created for all modules, regardless of location.

Note that all Minions at any location must be running the same features in order to make use of single topic.

For any reason, if you need to have different topic for each module or need different features on each minion,
you can disable single-topic as below.

Disabling Single topic must be configured on both Minion and OpenNMS.

.Disable single topic on `$\{MINION_HOME}/etc/org.opennms.core.ipc.rpc.kafka.cfg`
[source, properties]
----
single-topic=false
----

.Disable single topic on `$\{OPENNMS_HOME}/etc/opennms.properties.d/kafka.properties`
[source, properties]
----
org.opennms.core.ipc.rpc.kafka.single-topic=false
----
Create this file if it does not already exist.

== Disable the Kafka offset provider

{page-component-title} Core automatically monitors consumer offsets on Kafka to provide lag-related metrics.

To disable the monitoring of these metrics you can set the following property:

.Disable offset provider on `$\{OPENNMS_HOME}/etc/opennms.properties.d/kafka.properties`
[source, properties]
----
org.opennms.core.ipc.kafka.offset.disabled=true
----
