From 33c3015ef51e765ca23ff48ca73feb51e73c18e4 Mon Sep 17 00:00:00 2001 From: Ales Justin Date: Thu, 16 Jan 2025 10:20:34 +0100 Subject: [PATCH] Squash GrpcClientBuildItem's ClientInfo set per clientName --- .../grpc/deployment/GrpcClientProcessor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java index c88d1b4b995d3..c78dc05fbf084 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java @@ -218,8 +218,17 @@ void discoverInjectedClients(BeanDiscoveryFinishedBuildItem beanDiscovery, public void generateGrpcClientProducers(List clients, BuildProducer syntheticBeans) { + // squash all GrpcClientBuildItem's ClientInfo(s) per clientName + // so any extension could add own GrpcClientBuildItem(s) as well + Map> clientsMap = new HashMap<>(); for (GrpcClientBuildItem client : clients) { - for (ClientInfo clientInfo : client.getClients()) { + Set infos = clientsMap.computeIfAbsent(client.getClientName(), cn -> new HashSet<>()); + infos.addAll(client.getClients()); + } + + for (Map.Entry> entry : clientsMap.entrySet()) { + String clientName = entry.getKey(); + for (ClientInfo clientInfo : entry.getValue()) { if (clientInfo.type == ClientType.CHANNEL) { // channel @@ -227,7 +236,7 @@ public void generateGrpcClientProducers(List clients, // bean that provides the GrpcClientConfiguration for the specific service. ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(GrpcDotNames.CHANNEL) - .addQualifier().annotation(GrpcDotNames.GRPC_CLIENT).addValue("value", client.getClientName()) + .addQualifier().annotation(GrpcDotNames.GRPC_CLIENT).addValue("value", clientName) .done() .scope(Singleton.class) .unremovable() @@ -235,7 +244,7 @@ public void generateGrpcClientProducers(List clients, .creator(new Consumer<>() { @Override public void accept(MethodCreator mc) { - GrpcClientProcessor.this.generateChannelProducer(mc, client.getClientName(), clientInfo); + GrpcClientProcessor.this.generateChannelProducer(mc, clientName, clientInfo); } }) .destroyer(Channels.ChannelDestroyer.class); @@ -250,7 +259,6 @@ public void accept(MethodCreator mc) { syntheticBeans.produce(configurator.done()); } else { // blocking stub, mutiny stub, mutiny client - String clientName = client.getClientName(); ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(clientInfo.className) .addQualifier().annotation(GrpcDotNames.GRPC_CLIENT).addValue("value", clientName).done() // Only the mutiny client can use the Application scope, the others are "final" and so need Singleton.