Skip to content

Commit

Permalink
Merge pull request quarkusio#45736 from alesj/grpc_item_dups1
Browse files Browse the repository at this point in the history
Squash GrpcClientBuildItem's ClientInfo set per clientName
  • Loading branch information
geoand authored Jan 21, 2025
2 parents e707431 + 33c3015 commit f59ea88
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,33 @@ void discoverInjectedClients(BeanDiscoveryFinishedBuildItem beanDiscovery,
public void generateGrpcClientProducers(List<GrpcClientBuildItem> clients,
BuildProducer<SyntheticBeanBuildItem> syntheticBeans) {

// squash all GrpcClientBuildItem's ClientInfo(s) per clientName
// so any extension could add own GrpcClientBuildItem(s) as well
Map<String, Set<ClientInfo>> clientsMap = new HashMap<>();
for (GrpcClientBuildItem client : clients) {
for (ClientInfo clientInfo : client.getClients()) {
Set<ClientInfo> infos = clientsMap.computeIfAbsent(client.getClientName(), cn -> new HashSet<>());
infos.addAll(client.getClients());
}

for (Map.Entry<String, Set<ClientInfo>> entry : clientsMap.entrySet()) {
String clientName = entry.getKey();
for (ClientInfo clientInfo : entry.getValue()) {
if (clientInfo.type == ClientType.CHANNEL) {
// channel

// IMPORTANT: the channel producer relies on the io.quarkus.grpc.runtime.supports.GrpcClientConfigProvider
// 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()
.forceApplicationClass()
.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);
Expand All @@ -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.
Expand Down

0 comments on commit f59ea88

Please sign in to comment.