0

There is services which uses Kafka (by spring-cloud-stream-binder-kafka) in order to exchange messages. Services also uses Spring Config Server. All worked perfectly. I want to add Cloud Bus configurations updates with /monitor. When I added spring-cloud-starter-bus-kafka dependency - Kafka consumers stopped get messages. The question is: what am I doing wrong? What is right way to configure Cloud Bus with Kafka for project which already uses Spring Cloud Binder Kafka? I am not experienced with Kafka so please be detail.

Client pom.xml

...
    <properties>
        <java.version>19</java.version>
        <spring-cloud.version>2022.0.4</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-authorization-server</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.5.4</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.26</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>common</artifactId>
            <version>${project.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jobrunr</groupId>
            <artifactId>jobrunr-spring-boot-3-starter</artifactId>
            <version>6.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-kafka</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Client application.yml

spring:
...

  cloud:
    stream:
      bindings:
        signup-out-0:
          destination: signup
        signup-in-0:
          destination: signup
          group: user1
      source: signup

  kafka:
    bootstrap-servers:
      ${BROKER_HOST}: ${BROKER_PORT}

...

In case need of details the sources available on GitHub

Removing of dependency spring-cloud-starter-bus-kafka fixes the problem with consumers. But I expect this dependency should add Cloud Bus configuration broadcasting without breaking services messaging.

Update:

Logs diff

without dependency:

o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel signup-in-0
ConsumerConfig values: client.id = consumer-user1-1
group.id = user1

with dependency:

Registering MessageChannel springCloudBusInput
client.id = consumer-anonymous.3c0d339a-2479-46bc-b8ae-77d4e20929a2-1
group.id = anonymous.3c0d339a-2479-46bc-b8ae-77d4e20929a2

It seems that my consumer signup-in-0 message channel has been replaced with springCloudBusInput message channel. How configure it in order to not replace but add the channel?

I tried following changes in yml properties:

  cloud:
stream:
  bindings:
    signup-out-0:
      destination: signup
    signup-in-0:
      destination: signup
      group: user1
    springCloudBusInput:
      destination: my-bus-topic
      group: bus1

  source: signup;my-bus-topic
  function:
    definition: signup;my-bus-topic
  kafka:
    streams:
      binder:
        functions:
          my-bus-topic:
            applicationId: bus-consumer
          signup:
            applicationId: signup-consumer

But only result was renaming anonymous client.id and user.id for bus.

Andrey P.
  • 1
  • 1

0 Answers0