Skip to content
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

Squash GrpcClientBuildItem's ClientInfo set per clientName #45736

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading