My latest and most complete articles are in the pumpkin slow say, welcome to tea!

1 introduction

Spring Cloud Stream RabbitMQ and GCP Pubsub are very simple and the code is the same. This article explains the integration of Spring Cloud Stram with Kafka, which is also very simple.

Previous posts:

Spring Cloud Stream Binder with RabbitMQ for sending and receiving messages

“Integrating Spring Cloud Stream Binder with GCP Pubsub for Message sending and receiving”

2 install Kafka

To keep the demonstration simple, just install the Standalone version here, not the cluster. Download the installation package from the official website and decompress it to use.

Unzip the installation package$tar - XZF kafka_2. 13-2.8.0. TGZ# enter directory
$ cdKafka_2. 13-2.8.0 /# start the zookeeper
$ $ bin/ config/
# start kafka(new command line terminal)
$ bin/ config/
Copy the code

Both Zookeeper and Kafka use the default configuration, so you don’t need to change it. Logs are generated during startup. If no error message is displayed, the startup is successful.

3 integration

Introducing dependent dependencies:

Copy the code

Implement simple Publisher and Consumer:


public class StreamBinderKafka {
    private static final Logger log = LoggerFactory.getLogger(StreamBinderKafka.class);
    public static void main(String[] args) {, args);

    public Supplier<String> pkslowSource(a) {
        return () -> {
            String message = "";
  "Sending value: " + message);
            return message;

    public Consumer<String> pkslowSink(a) {
        return message -> {
  "Received message "+ message); }; }}Copy the code

Configure the required attributes as follows:

        definition: pkslowSource; pkslowSink
         destination: pkslow-topic
          destination: pkslow-topic
        fixed-delay: 500
          brokers: localhost:9092
          auto-create-topics: true
          required-acks: 1
Copy the code

Run logs are as follows:

4 summarizes

The integration of the three MQS makes almost no difference and does not require major code changes, which is the benefit of Spring Cloud Stream.

Please check the code:…

Welcome to pay attention to the wechat public number “Pumpkin slow Talk”, will continue to update for you…

Read more and share more; Write more. Organize more.