The last article has introduced the use of Docker deployment canal service, the implementation of MySQL database binlog log parsing, and the official provided client program successfully read the message. This is not yet possible in a production environment; it is better to send messages to a message queue and then consume them from the message queue.

Here I have chosen RabbitMQ.

Only Kafka and RocketMQ are supported, but RabbitMQ is now available in 1.1.5 and is already mirrored.

For Docker deployment, just pull the latest image.

Configuration canal

Step 1 Pull mirror:

# docker pull canal/canal-server:latest
Copy the code

Then start the container and copy the configuration file from the container:

# docker cp canal-server:/home/admin/canal-server/conf/canal.properties ./
# docker cp canal-server:/home/admin/canal-server/conf/test/instance.properties ./
Copy the code

Modify the canal.properties file to configure output to RabbitMQ with the following changes:

# specify the RabbitMQ
canal.serverMode = rabbitMQ

# the RabbitMQ configuration
rabbitmq.host = 127.0. 01.
rabbitmq.virtual.host = /
rabbitmq.exchange = exchange.canal
rabbitmq.username = xxxx
rabbitmq.password = xxxx
Copy the code

There are two points to note here. One is that many of the articles I found on the web about RabbitMQ configuration are as follows:

canal.mq.servers = xxx canal.mq.vhost = / canal.mq.exchange = exchange.canal canal.mq.username = admin canal.mq.password  = adminCopy the code

However, I did not succeed in this configuration, or it may be the version problem, I did not have more verification.

The second is that the RabbitMQ configuration does not currently support ports, so you can only use the default port 5672.

Next modify the instance.properties file:

MySQL > select * from 'MySQL'
canal.instance.master.address=host:port
canal.instance.dbUsername=xxxx
canal.instance.dbPassword=xxxx
Routing key for RabbitMQ
canal.mq.topic=canal-routing-key
Copy the code

Docker – compose documents:

version: '3'

services:
  canal-server:
    image: canal/canal-server
    container_name: canal-server
    restart: unless-stopped
    network_mode: host
    ports: 
      - 11111:11111
    volumes:
      - ./canal.properties:/home/admin/canal-server/conf/canal.properties
      - ./instance.properties:/home/admin/canal-server/conf/test/instance.properties
      - ./log/:/home/admin/canal-server/logs/
Copy the code

When everything is ready, start the service:

# docker-compose up -d
Copy the code

Configure the RabbitMQ

Create a new exchange:

Then create a new queue:

Finally bind the queue:

Note that the Routing key must be the same as that configured before.

At this point, if everything goes well you should have a message in the queue.

Reference Documents:

www.siques.cn/doc/340