DEV Community

Cover image for Start Maxwell with Namespaced Topic Kafka Producer (Look for Idle Listeners in Kafka)
Montana Mendy
Montana Mendy

Posted on

Start Maxwell with Namespaced Topic Kafka Producer (Look for Idle Listeners in Kafka)

After running through the prerequisites, you will have:

  • A AWS Aurora instance
  • A Maxwell image named osheroff/maxwell
  • AKafka service named kafka, listening on kafka:9092

Start Maxwell with Namespaced Topic Kafka Producer
This is a slight variation of the prerequisite, AWS Aurora to Maxwell Kafka Producer.

In the prerequisite we ran Maxwell with the default Kafka Producer configuration which will produce messages on the Maxwell topic.

You'll want to get the number of messages in a Maxwell topic, you can run: bin/ --broker-list localhost:9092 --topic mytopic --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'

In this example we are overriding the MAXWELL_OPTIONS environment variable and specifying a dynamic topic name, so that Maxwell will route messages from each table to topics by the same name, namespaced by the database name.

docker run -it --rm \
    --link kafka \
    --env KAFKA_HOST=kafka \
    --env KAFKA_PORT=9092 \
    --env MAXWELL_OPTIONS="--kafka_topic=maxwell_%{database}_%{table}
    --name maxwell \
Enter fullscreen mode Exit fullscreen mode

Image description

Here's a graphical way of looking at things when it comes to Consumers. Now let's get back to Maxwell.

This will be the output of Maxwell:

17:44:34,901 INFO  ProducerConfig - ProducerConfig values: = 30000 = 100
    buffer.memory = 33554432
    ssl.truststore.password = null
    batch.size = 16384
    ssl.keymanager.algorithm = SunX509
    receive.buffer.bytes = 32768
    ssl.cipher.suites = null
    ssl.key.password = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    ssl.provider = null = null = 5
    sasl.kerberos.ticket.renew.window.factor = 0.8
    bootstrap.servers = [kafka:9092] = 
    max.request.size = 1048576
    acks = 1 = 0
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1] = 60000
    ssl.endpoint.identification.algorithm = null
    ssl.keystore.location = null
    value.serializer = class org.apache.kafka.common.serialization.StringSerializer
    ssl.truststore.location = null
    ssl.keystore.password = null
    key.serializer = class org.apache.kafka.common.serialization.StringSerializer
    block.on.buffer.full = false = 30000 = 300000
    security.protocol = PLAINTEXT
    ssl.protocol = TLS
    sasl.kerberos.min.time.before.relogin = 60000 = 30000 = 540000
    ssl.trustmanager.algorithm = PKIX
    metric.reporters = []
    compression.type = none
    ssl.truststore.type = JKS = 60000
    retries = 0
    send.buffer.bytes = 131072
    partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner = 50
    metrics.num.samples = 2
    ssl.keystore.type = JKS

17:44:34,952 INFO  AppInfoParser - Kafka version :
17:44:34,952 INFO  AppInfoParser - Kafka commitId : 23c69d62a0cabf06
17:44:35,012 INFO  Maxwell - Maxwell v1.7.0 is booting (MaxwellKafkaProducer), starting at BinlogPosition[mysql-bin-changelog.000002:84337]
17:44:35,680 INFO  MysqlSavedSchema - Restoring schema id 1 (last modified at BinlogPosition[mysql-bin-changelog.000002:3521])
17:44:38,991 INFO  OpenReplicator - starting replication at mysql-bin-changelog.000002:84337
Enter fullscreen mode Exit fullscreen mode

Image description

The process is now waiting for new data events and looking for idle Kafka listeners.

Start a consumer (in another terminal window). This command will start an unnamed instance of Spotify/Kafka linked to the Kafka service, start a consumer, display existing messages from the Maxwell topic, and wait for new messages until you quit (which destroys the container):

docker run -it --rm --link kafka spotify/kafka /opt/kafka_2.11- --bootstrap-server kafka:9092 --topic maxwell_{AURORA_DATABASE}_{AURORA_TABLE} --from-beginning
Enter fullscreen mode Exit fullscreen mode

Connect to the AWS Aurora instance, insert some records, and update some records. Data events from Maxwell will be printed in the Consumer terminal window:

Enter fullscreen mode Exit fullscreen mode

Top comments (0)