admin管理员组

文章数量:1122846

I use Spring Cloud Stream v4.

Here is my application.yml code:

spring:
 cloud:
   stream:
     kafka:
       binder:
         configuration:
           key.serializer: org.apache.kafkamon.serialization.StringSerializer
           key.deserializer: org.apache.kafkamon.serialization.StringDeserializer
     bindings:
       userUpdatedCluster1-in-0:
         destination: test-1
         binder: kafkaCluster1
         group: xx
       userUpdatedCluster2-in-0:
         destination: test2
         binder: kafkaCluster2
         group: yy
     binders:
       kafkaCluster1:
         type: kafka
         environment:
           spring:
             kafka:
               bootstrap-servers: public--dev.abcd:23100
               properties:
                 security.protocol: PLAINTEXT
       kafkaCluster2:
         type: kafka
         environment:
           spring:
             kafka:
               bootstrap-servers: public--dev.efgh:23100
               properties:
                 security.protocol: PLAINTEXT

And here is my consumer:

@Component("userUpdatedCluster1")
public class UserUpdatedEventConsumer implements Consumer<Message<UserUpdatedEvent>> {

   private final UserService userService;

   public UserUpdatedEventConsumer(UserService userService) {
       this.userService = userService;
   }

   @Override
   public void accept(Message<UserUpdatedEvent> message) {
       UserUpdatedEvent event = message.getPayload();
       userService.printUpdatedUserInfo(event.id(), event.name(), event.age());
   }
}

With this setup, my consumer can successfully consume messages from userUpdatedCluster1-in-0 binding and it successfully consumes from userUpdatedCluster2-in-0 binding if I change the consumer bean name accordingly.

Question: As I have same message structure in both cluster topics, I want to find out whether it is possible to have such configuration so that a single consumer bean consumes messages from both bindings at the same time without declaring separate beans per binding.

本文标签: