Appendix #2: Tips and tricks
Making this tutorial took quite a lot of time for us. We want to collect some useful tips and tricks here for those who decide to play with the final example. Feel free to contribute if you find something which could help others.
Point to Centrifugo running on host (outside Docker)
We did this ourselves while experimenting and measuring latency numbers in different scenarios. If you want to run the example, but need to point backend or Nginx to look at Centrifugo on your machine outside Docker, then you can use:
- On Linux run
ifconfigand finddocker0interface – use its ip address to point to Centrifugo. In our case it was172.17.0.1, so we pointed Nginx to172.17.0.1:8000upstream (Centrifugo runs on port 8000 by default), and in Django code usedhttp://172.17.0.1:8000/api/broadcastendpoint. Also, make sure you are using"address": "0.0.0.0"in Centrifugo configuration - On Macos – use
host.docker.internalspecial name, i.e.host.docker.internal:8000in Nginx andhttp://host.docker.internal:8000/api/broadcastas API endpoint for Django code.
Connect to PosgreSQL
Run from within example repo root:
docker compose exec db psql postgresql://grandchat:grandchat@localhost:5432/grandchat
Inspect dockerized Kafka state
List current Kafka topics (run from within example repo root):
docker compose exec kafka kafka-topics --bootstrap-server kafka:9092 --list
Describe the state of Kafka topic:
docker compose exec kafka kafka-topics --bootstrap-server kafka:9092 --describe --topic postgres.public.chat_cdc
Show state of consumer group – partitions, lag, offsets (centrifugo is a name of consumer group in our case):
docker compose exec kafka kafka-consumer-groups --bootstrap-server kafka:9092 --describe --group centrifugo
Tail new messages in topic:
docker compose exec kafka kafka-console-consumer --bootstrap-server kafka:9092 --topic postgres.public.chat_cdc
Pause Kafka Connect
Or any other service in Docker compose when you need to test failure scenarios (use name of service from docker-compose.yml):
docker compose pause connect
To run again:
docker compose unpause connect