A library implementing the Divo Stack behaviour, providing a pre-configured Kafka cluster via docker-compose for integration testing Elixir apps. The cluster is a single-node kafka/zookeeper compose stack that can be configured with an arbitrary list of topics to create on first start and the hostname/IP address the cluster exposes to outside hosts.
Requires inclusion of the Divo library in your mix project.
The package can be installed by adding divo
and divo_kafka
to your list of dependencies in mix.exs
:
def deps do
[
{:divo, "~> 2.0.0"},
{:divo_kafka, "~> 1.0.1"}
]
end
In your Mix environment exs file (i.e. config/integration.exs), include the following:
config :myapp,
divo: [
{DivoKafka, [create_topics: "my-data:1:1", outside_host: "ci-host"]}
]
In your integration test specify that you want to use Divo:
use Divo
...
The resulting stack will create a single-node Kafka and Zookeeper instance with Zookeeper exposing port 2181 to the host and Kafka exposing port 9092 to the host.
You may omit the configuration arguments to DivoKafka and still have a working stack.
-
create_topics
: A string of the formtopic1-name:1:1,topic2-name:1:1
which will ensure the list of topics are created at first start of the cluster. Defaults toclusterready:1:1
to allow for readiness checking of the cluster. -
outside_host
: The hostname or IP address by which hosts external to the Kafka cluster can reach it (in this case, your app). Defaults tolocalhost
but may cause problems when running in a CI system, particularly a containerized one. In such circumstances, it is recommended to use an address or name that is routable even if ExUnit will be running inside a container. -
auto_topic
: Whether or not topics will be created, if missing, when producing or consuming messages. Note that the topics supplied increate_topics
will be created, on startup, regardless of this config setting. Defaults totrue
. -
kafka_image_version
: The kafka image (wurstmeister/kafka) version to use. A list of available versions can be found on their dockerhub tags page. Defaults tofalse
See Divo GitHub or Divo Hex Documentation for more instructions on using and configuring the Divo library. See wurstmeister/kafka and wurstmeister/zookeeper for further documentation on using and configuring the features of these images.
Released under Apache 2 license.