Skip to content

Slightly improve the way Arc is used in gRPC #47175

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
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 @@ -52,6 +52,7 @@
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.BeanInfo;
import io.quarkus.arc.processor.BeanStream;
import io.quarkus.arc.processor.BuiltinScope;
import io.quarkus.deployment.ApplicationArchive;
import io.quarkus.deployment.Capabilities;
Expand Down Expand Up @@ -696,8 +697,8 @@ ServiceStartBuildItem initializeServer(GrpcServerRecorder recorder,
VertxWebRouterBuildItem routerBuildItem,
VertxBuildItem vertx, Capabilities capabilities,
List<FilterBuildItem> filterBuildItems,
// used to ensure that gRPC server starts after OTel has been set up
@SuppressWarnings("unused") BeanContainerBuildItem beanContainerBuildItem) {
ValidationPhaseBuildItem validationPhase,
BeanContainerBuildItem beanContainerBuildItem) {

// Build the list of blocking methods per service implementation
Map<String, List<String>> blocking = new HashMap<>();
Expand Down Expand Up @@ -733,7 +734,16 @@ ServiceStartBuildItem initializeServer(GrpcServerRecorder recorder,
} else {
routerRuntimeValue = routerBuildItem.getHttpRouter();
}
recorder.initializeGrpcServer(vertx.getVertx(), routerRuntimeValue,
Type bindableServiceType = Type.create(GrpcDotNames.BINDABLE_SERVICE, org.jboss.jandex.Type.Kind.CLASS);
BeanStream bindableServiceBeanStream = validationPhase.getContext().beans().classBeans()
.matchBeanTypes(new Predicate<>() {
@Override
public boolean test(Set<Type> types) {
return types.contains(bindableServiceType);
}
});
recorder.initializeGrpcServer(bindableServiceBeanStream.isEmpty(), beanContainerBuildItem.getValue(),
vertx.getVertx(), routerRuntimeValue,
config, shutdown, blocking, virtuals, launchModeBuildItem.getLaunchMode(),
capabilities.isPresent(Capability.SECURITY), securityHandlers);
return new ServiceStartBuildItem(GRPC_SERVER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.Subclass;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.grpc.api.ServerBuilderCustomizer;
import io.quarkus.grpc.auth.GrpcSecurityInterceptor;
import io.quarkus.grpc.reflection.service.ReflectionServiceV1;
Expand Down Expand Up @@ -121,18 +122,15 @@ public void handle(RoutingContext event) {
}
}

public void initializeGrpcServer(RuntimeValue<Vertx> vertxSupplier,
public void initializeGrpcServer(boolean hasNoBindableServiceBeans, BeanContainer beanContainer,
RuntimeValue<Vertx> vertxSupplier,
RuntimeValue<Router> routerSupplier,
GrpcConfiguration cfg,
ShutdownContext shutdown,
Map<String, List<String>> blockingMethodsPerService,
Map<String, List<String>> virtualMethodsPerService,
LaunchMode launchMode, boolean securityPresent, Map<Integer, Handler<RoutingContext>> securityHandlers) {
GrpcContainer grpcContainer = Arc.container().instance(GrpcContainer.class).get();
if (grpcContainer == null) {
throw new IllegalStateException("gRPC not initialized, GrpcContainer not found");
}
if (hasNoServices(grpcContainer.getServices()) && LaunchMode.current() != LaunchMode.DEVELOPMENT) {
if (hasNoBindableServiceBeans && LaunchMode.current() != LaunchMode.DEVELOPMENT) {
LOGGER.error("Unable to find beans exposing the `BindableService` interface - not starting the gRPC server");
return; // OK?
}
Expand All @@ -152,20 +150,23 @@ public void initializeGrpcServer(RuntimeValue<Vertx> vertxSupplier,
// start single server, not in a verticle, regardless of the configuration.instances
// for reason unknown to me, verticles occasionally get undeployed on dev mode reload
if (GrpcServerReloader.getServer() != null || (provider != null && provider.serverAlreadyExists())) {
devModeReload(grpcContainer, vertx, configuration, provider, blockingMethodsPerService,
devModeReload(beanContainer.beanInstance(GrpcContainer.class), vertx, configuration, provider,
blockingMethodsPerService,
virtualMethodsPerService, shutdown);
} else {
devModeStart(grpcContainer, vertx, configuration, provider, blockingMethodsPerService,
devModeStart(beanContainer.beanInstance(GrpcContainer.class), vertx, configuration, provider,
blockingMethodsPerService,
virtualMethodsPerService, shutdown,
launchMode);
}
} else {
prodStart(grpcContainer, vertx, configuration, provider, blockingMethodsPerService, virtualMethodsPerService,
prodStart(beanContainer.beanInstance(GrpcContainer.class), vertx, configuration, provider,
blockingMethodsPerService, virtualMethodsPerService,
launchMode);
}
} else {
buildGrpcServer(vertx, configuration, routerSupplier, shutdown, blockingMethodsPerService, virtualMethodsPerService,
grpcContainer, launchMode, securityPresent, securityHandlers);
beanContainer.beanInstance(GrpcContainer.class), launchMode, securityPresent, securityHandlers);
}
}

Expand Down
Loading