-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Listeners throws javax.management.InstanceAlreadyExistsException #398
Comments
Looks like a regression - I will create M2 today. |
We failed to backport this commit. |
This is fixed in 1.3.0.BUILD-SNAPSHOT; I will release M2 soon. |
1.3.0.M2 is available in the milestone repo. |
I tested with 1.3.0.M2 version and it is fixed. Thanks |
Hi, with org.springframework.kafka:spring-kafka:jar:2.1.8.RELEASE:compile I see the same error: stack trace is: Repository.addMBean(DynamicMBean, ObjectName, Repository$RegistrationContext) line: 437 I think part of the problem is that org.springframework.kafka.config.KafkaListenerEndpointRegistry.start() does create a separate container for each registered endpoint, i.e. @KafkaListener annotation, but the DefaultKafkaConsumerFactory uses the same clientId (resp. clientId prefx/suffix) for all containers created, resulting in AppInfoParser to register the same mbean id. I'm not sure what a good solution for this problem would be, I ended up with this hack:
`` |
@garyrussell do you see above comment for an already close issue? |
This will only happen if you explicitly set the client id in the application properties/yml (otherwise the kafka clients generate the client id). If you have multiple listeners created from the same factory, use the @SpringBootApplication
public class Kgh398Application {
public static void main(String[] args) {
SpringApplication.run(Kgh398Application.class, args);
}
@KafkaListener(id = "kgh3981", topics = "kgh398", clientIdPrefix = "${spring.kafka.consumer.client-id}-listen1")
public void listen1(String in) {
System.out.println(in);
}
@KafkaListener(id = "kgh3982", topics = "kgh398", clientIdPrefix = "${spring.kafka.consumer.client-id}-listen2")
public void listen2(String in) {
System.out.println(in);
}
@Bean
public NewTopic topic() {
return TopicBuilder.name("kgh398").partitions(1).replicas(1).build();
}
} 2.1.x is no longer supported; 2.3.x is the oldest supported version. |
Mhhh... we do not set clientId anywhere, the default seems to be consumer-0, etc. We need to update our components anyway, so I will try to update one component next week, and retest. One question: |
There are 4 places it can be specified. Consumer factory If it's not specified anywhere, it's generated by the String groupInstanceIdPart = groupInstanceId != null ? groupInstanceId : CONSUMER_CLIENT_ID_SEQUENCE.getAndIncrement() + "";
String generatedClientId = String.format("consumer-%s-%s", groupId, groupInstanceIdPart); If it is specified in the above 4 places, the last one is supposed to win, but with the #1770 bug, it is set to an empty string by the endpoint (if not set), overriding the container factory property. So, if you explicitly set a client id (anywhere), and you have multiple listeners then, yes, it needs to be made unique for each listener, either by setting it on the factory.setContainerCustomizer(container -> {
container.getContainerProperties().setClientId("client-for-"
+ container.getContainerProperties().getTopics()[0]);
}); |
Many thanks for the explanation, very helpful. |
I get javax.management.InstanceAlreadyExistsException when I have multiple listeners. It works fine in 1.2.2.RELEASE, but throws this exception in 1.3.0.M1 version or 1.3.0.BUILD-SNAPSHOT. I think the problem is consumers don't get a generated id like 'consumer-1', 'consumer-2':
The text was updated successfully, but these errors were encountered: