0

I am using Spring Cloud Stream in my project.

I did not give group id to my consumers due to my need. That's why group id's are given automatically(anonoymous group id) by spring cloud stream. But I need to use this group id in my runtime. Is there any way I can get this group id?

I tried the following codes, but the return value null. Whereas group id is not null. Spring cloud stream gave a random value but I didn't get it.

@Autowired
private BindingService bindingService;
    
String groupId = bindingService.getBindingServiceProperties()
.getBindings().get("person-topic-in").getGroup();

I reviewed the source code of Spring Cloud Stream. I need the group id that I show in the image below. Is there any way I can achieve this in Runtime?

enter image description here

omerstack
  • 535
  • 9
  • 23
  • Why not **give** a group name? Then it **wont** be anonymous? – OneCricketeer Aug 04 '22 at 21:42
  • I'm running multiple Scalable services and I don't want them to get the same group IDs. That's why I don't give group id. But for some reason I need these group ids at runtime. – omerstack Aug 04 '22 at 21:45
  • 1
    I would probably need a better understanding of your actual business problem given that anonymous group ID is only used for testing and/or simple scenarios where groupid is not relevant. Otherwise as others suggested you assign it. In fact if you are scaling then you definitely want to have multiple consumers with the same group id for load balancing – Oleg Zhurakousky Aug 05 '22 at 14:08

1 Answers1

0

There is the logic like this in the Apache Kafka Binder implementation:

else {
        ((ListenerContainerCustomizer<Object>) customizer)
                .configure(messageListenerContainer, destination.getName(), consumerGroup);
    }

So, if you can provide that ListenerContainerCustomizer, you can catch a mapping of a destination to consumerGroup.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118