Springboot and Kafka clusters

Time:2021-11-30

preface

There are quite a lot of Message Queuing Middleware management in the market, such as ActiveMQ, rabbitmq, zeromq, Kafka, metamq and rocketmq, but Kafka may be my first contact. At that time, I only knew some practical things for use. I spent a little time looking at them these two days.

Message queue

In my opinion, the emergence of message queues is moreDecoupling, we don’t need to care about the source and source of data. Producers and consumers may not know what kind of existence the other party is, and solve sudden problemsData surgeI have experimented with this in my example

  1. The thread runs for a while and sleeps for 20ms
  2. The thread has been running

Springboot and Kafka clusters

The processing speed of Experiment 1 can keep up with the production speed, and the offset always points to end, but the production speed of Experiment 2 increases sharply, and the processing speed obviously can’t keep up. After I stop production and look again for a few milliseconds, the offset points to end.

example

It may be faster to understand through examples. Here I use the Kafka cluster built by docker compose

Springboot and Kafka producers

https://github.com/tokeneros/kafka_produce…

Springboot and Kafka consumers

https://github.com/tokeneros/kafka_consumt…

This work adoptsCC agreement, reprint must indicate the author and the link to this article