Waterstream Quick Start
=======================

To try out Waterstream on your computer please follow the next steps

Prerequisites
-------------

- `Confluent Platform <https://docs.confluent.io/current/installation/index.html#installation-overview>`_ 4.0.1 or newer.
- `Confluent CLI <https://docs.confluent.io/current/cli/installing.html#cli-install>`_
- `Docker <https://docs.docker.com/get-docker/>`_
- License file for the Waterstream - `contact us <https://waterstream.io/try-waterstream/>`_ if you don't have one yet. You can get a license for development or small-scale personal use for free.

If you don't have Confluent Platform and Confluent CLI on your machine you can use docker-compose as an alternative - this will be described later on.

Start dependencies
------------------

This guide assumes that you have Zookeeper and Kafka running locally on default ports (2181 and 9092 respectively).
You can use `Confluent CLI`_ to start them all together:

.. code-block:: bash

   bin/confluent local start kafka

or individually:

.. code-block:: bash

   bin/zookeeper-server-start ./etc/kafka/zookeeper.properties
   bin/kafka-server-start ./etc/kafka/server.properties

See `Confluent Platform quickstart <https://docs.confluent.io/current/quickstart/index.html#quickstart>`_ for more details.

Create Kafka topics
-------------------

You can create the necessary Kafka topics using Confluent CLI:

.. code-block:: bash

   kafka-topics --bootstrap-server localhost:9092 --create \
     --topic mqtt_sessions --partitions 5 --replication-factor 1 \
     --config cleanup.policy=compact \
     --config min.compaction.lag.ms=60000 --config delete.retention.ms=600000
   kafka-topics --bootstrap-server localhost:9092 --create \
     --topic mqtt_retained_messages --partitions 5 --replication-factor 1 \
     --config cleanup.policy=compact \
     --config min.compaction.lag.ms=60000 --config delete.retention.ms=600000
   kafka-topics --bootstrap-server localhost:9092 --create \
     --topic mqtt_connections --partitions 5 --replication-factor 1 \
     --config cleanup.policy=delete --config retention.ms=600000
   kafka-topics --bootstrap-server localhost:9092 --create \
     --topic mqtt_messages --partitions 5 --replication-factor 1 \
     --config retention.ms=86400000
   kafka-topics --bootstrap-server localhost:9092 --create \
     --topic __waterstream_heartbeat --partitions 5 --replication-factor 1 \
     --config retention.ms=300000

If you don't have Confluent CLI on your machine you can use Docker image to do the same thing:

.. code-block:: bash

   docker run -ti --network=host confluentinc/cp-kafka:4.0.1 /usr/bin/kafka-topics --bootstrap-server localhost:9092 --create --topic mqtt_sessions \
     --partitions 5 --replication-factor 1 --config cleanup.policy=compact \
     --config min.compaction.lag.ms=60000 --config delete.retention.ms=600000
   docker run -ti --network=host confluentinc/cp-kafka:4.0.1 /usr/bin/kafka-topics --bootstrap-server localhost:9092 --create --topic mqtt_retained_messages \
     --partitions 5 --replication-factor 1 --config cleanup.policy=compact \
     --config min.compaction.lag.ms=60000 --config delete.retention.ms=600000
   docker run -ti --network=host confluentinc/cp-kafka:4.0.1 /usr/bin/kafka-topics --bootstrap-server localhost:9092 --create --topic mqtt_connections \
     --partitions 5 --replication-factor 1 --config cleanup.policy=delete \
     --config retention.ms=600000
   docker run -ti --network=host confluentinc/cp-kafka:4.0.1 /usr/bin/kafka-topics --bootstrap-server localhost:9092 --create --topic mqtt_messages \
     --partitions 5 --replication-factor 1 --config retention.ms=86400000
   docker run -ti --network=host confluentinc/cp-kafka:4.0.1 /usr/bin/kafka-topics --bootstrap-server localhost:9092 --create --topic __waterstream_heartbeat \
     --partitions 5 --replication-factor 1 --config retention.ms=300000

Start Waterstream
-----------------
Assuming that Waterstream license file is in current directory and named ``waterstream.license``
run following command to start Waterstream:

.. code-block:: bash
   :substitutions:

   docker run -it --rm \
     -e KAFKA_BOOTSTRAP_SERVERS=PLAINTEXT://localhost:9092 \
     -e MQTT_PORT=1883 \
     -e SESSION_TOPIC=mqtt_sessions \
     -e RETAINED_MESSAGES_TOPIC=mqtt_retained_messages \
     -e CONNECTION_TOPIC=mqtt_connections \
     -e KAFKA_MESSAGES_DEFAULT_TOPIC=mqtt_messages \
     -v `pwd`/waterstream.license:/etc/waterstream.license:ro \
     --network host \
     --name waterstream-kafka simplematter/waterstream-kafka:|release|


Logs will be displayed in the console. If you want to run in the background instead - replace ``-it`` with ``-d``.
If you want to keep the container after termination - remove ``--rm`` flag.

More configuration parameters documentation available :doc:`here <configGuide>`

Start Waterstream on ARM64 platform
-----------------------------------

Everything remains the same, except of Docker image - use ``simplematter/waterstream-kafka-arm64v8``.
The command to start Waterstream will look like this:

.. code-block:: bash
   :substitutions:

   docker run -it --rm \
     -e KAFKA_BOOTSTRAP_SERVERS=PLAINTEXT://localhost:9092 \
     -e MQTT_PORT=1883 \
     -e SESSION_TOPIC=mqtt_sessions \
     -e RETAINED_MESSAGES_TOPIC=mqtt_retained_messages \
     -e CONNECTION_TOPIC=mqtt_connections \
     -e KAFKA_MESSAGES_DEFAULT_TOPIC=mqtt_messages \
     -v `pwd`/waterstream.license:/etc/waterstream.license:ro \
     --network host \
     --name waterstream-kafka simplematter/waterstream-kafka-arm64v8:|release|