0

So I've been trying to set up a kafka stream using Debezium connectors as per Debezium's tutorial on their website. I manage to successfully link the Debezium to my MySQL database that's running in GCP and the watcher prints out the messages but the python consumer I've built does not. Any help would profoundly appreciated!

Here is my Python Consumer:

from kafka import KafkaConsumer

consumer = KafkaConsumer(
    'test_server.testDB.test_table',
    bootstrap_servers=['localhost:9092'],
    auto_offset_reset='earliest'
)

print(consumer.bootstrap_connected())
print(consumer.subscription())
for message in consumer:
    print(message)

(venv) consumer % python consumer.py 
True
{'test_server.testDB.test_table'}

But then it doesn't print the messages for some reason...

However, the watcher which I created using the following command, does:

docker run -it --rm --name watcher --link zookeeper:zookeeper --link kafka:kafka quay.io/debezium/kafka:1.9 watch-topic -a -k test_server.testDB.test_table

WARNING: Using default NODE_ID=1, which is valid only for non-clustered installations.
Starting in ZooKeeper mode using NODE_ID=1.
Using ZOOKEEPER_CONNECT=172.17.0.2:2181
Using configuration config/server.properties.
Using KAFKA_LISTENERS=PLAINTEXT://172.17.0.6:tcp://172.17.0.3:9092 and KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.17.0.6:9092
Using KAFKA_BROKER=172.17.0.3:9092
Contents of topic test_server.testDB.test_table:
{"schema":{"type":"struct","fields":[{"type":"int32" ......

I used the following commands to create each of the following containers:

Zookeeper:

docker run -it --rm --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 quay.io/debezium/zookeeper:1.9

Kafka:

docker run -it --rm --name kafka -p 9092:9092 --link zookeeper:zookeeper quay.io/debezium/kafka:1.9

Kafka-Connect/Debezium:

docker run -it --rm --name connect -p 8083:8083 -e GROUP_ID=1 -e CONFIG_STORAGE_TOPIC=my_connect_configs -e OFFSET_STORAGE_TOPIC=my_connect_offsets -e STATUS_STORAGE_TOPIC=my_connect_statuses --link zookeeper:zookeeper --link kafka:kafka --quay.io/debezium/connect:1.9

Connection details:

curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" localhost:8083/connectors/ -d '{ "name": "test-connector", "config": { "connector.class": "io.debezium.connector.mysql.MySqlConnector", "tasks.max": "1", "database.hostname": "host.docker.internal", "database.port": "REDACTED", "database.user": "REDACTED", "database.password": "REDACTED", "database.server.id": "REDACTED", "database.server.name": "test_server", "database.include.list": "testDB", "database.history.kafka.bootstrap.servers": "kafka:9092", "database.history.kafka.topic": "dbhistory.testDB" } }'

Watcher:

docker run -it --rm --name watcher --link zookeeper:zookeeper --link kafka:kafka quay.io/debezium/kafka:1.9 watch-topic -a -k test_server.testDB.test_table
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
mj8701
  • 21
  • 7
  • The watcher works because it is running inside the Docker network, where it can connect... Seems like your Python client is not actually "connected". See https://stackoverflow.com/questions/51630260/connect-to-kafka-running-in-docker – OneCricketeer Jun 23 '22 at 19:58
  • hi @ma8701 did you get this to work? i ran into same issue. – Spencer Trinh Mar 09 '23 at 03:13
  • @SpencerTrinh sorry was such a long time ago, I don't remember how I fixed it :/ – mj8701 Mar 14 '23 at 14:23

0 Answers0