Skip to main content

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 that 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 ifconfig and find the docker0 interface – use its ip address to point to Centrifugo. In our case it was 172.17.0.1, so we pointed the Nginx upstream to 172.17.0.1:8000 (Centrifugo runs on port 8000 by default) and set CENTRIFUGO_HTTP_API_ENDPOINT = 'http://172.17.0.1:8000' in backend/app/settings.py. Also make sure you use "address": "0.0.0.0" in the Centrifugo configuration.
  • On macOS – use the host.docker.internal special name: host.docker.internal:8000 for the Nginx upstream and CENTRIFUGO_HTTP_API_ENDPOINT = 'http://host.docker.internal:8000' in backend/app/settings.py.

Both Nginx upstream variants are already present as commented lines in nginx/nginx.conf, so you only need to uncomment the one for your OS.

Centrifugo admin web UI

Centrifugo ships with a built-in admin web UI, enabled in centrifugo/config.json. With the default Docker Compose setup it's available at http://localhost:8000 – log in with the password from the admin section of the config (password by default). From there you can inspect connected clients and channels, see node metrics, and publish test messages into a channel by hand – handy for poking at the app without touching the backend.

Connect to PostgreSQL

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