Hi all. I'm just getting started with Cerbos. I've...
# help
j
Hi all. I'm just getting started with Cerbos. I've read through most of the quickstart and have been testing with curl. But now that I'm trying to get it integrated into our app I'm having all sorts of problems with grpc. We are using Quarkus. I created a basic quarkus hello world starter project which uses the latest Quarkus (3.11.x):
Copy code
quarkus create && cd code-with-cerbos
I modified the basic GreetingResource endpoint with the
CerbosBlockingClient
sample code and that all compiles fine. I modified pom.xml dependencies:
Copy code
<dependency>
      <groupId>dev.cerbos</groupId>
      <artifactId>cerbos-sdk-java</artifactId>
      <version>0.12.0</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-core</artifactId>
      <version>1.63.0</version>
      <scope>runtime</scope>
    </dependency>
I'm not familiar with grpc. I've tried various scopes with grpc-core and nothing seemed to fix the issue. When I hit that endpoint I'm getting:
Copy code
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2024-06-25 11:12:45,827 INFO  [io.quarkus] (Quarkus Main Thread) code-with-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.11.3) started in 2.605s. Listening on: <http://localhost:8080>

2024-06-25 11:12:45,830 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2024-06-25 11:12:45,831 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, rest, smallrye-context-propagation, vertx]
2024-06-25 11:13:05,979 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /hello/ failed, error id: 0b17d221-b74b-409d-b605-28103aba9d4b-1: java.lang.NoClassDefFoundError: com/google/protobuf/RuntimeVersion$RuntimeDomain
	at dev.cerbos.api.v1.engine.Engine$Principal.<clinit>(Engine.java:15736)
	at dev.cerbos.sdk.builders.Principal.<init>(Principal.java:17)
	at dev.cerbos.sdk.builders.Principal.newInstance(Principal.java:21)
	at org.acme.GreetingResource.hello(GreetingResource.java:26)
	at org.acme.GreetingResource$quarkusrestinvoker$hello_e747664148511e1e5212d3e0f4b40d45c56ab8a1.invoke(Unknown Source)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:599)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: com.google.protobuf.RuntimeVersion$RuntimeDomain
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:526)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:476)
t
Seem Quarkus using older version of grpc. I think you should exluce grpc from Quarkus, then override its as you did.
j
Thanks Theon, I tried to rule that out by generating a dependency report. I don't see reference to grpc, protobuf, etc related to Quarkus.
t
I got the class not found problem and found that my Quarkus use older grpc, protobuf version when checking in external libraries. So I forced to use newer version in Gradle, hope it can help.
Copy code
api(enforcedPlatform("com.google.protobuf:protobuf-bom:4.26.1"))
    api(enforcedPlatform("io.grpc:grpc-bom:1.63.0"))
j
thanks, I'll take a look. I'm considering sticking with the REST API for simplicity.
@Thịnh Trần thanks that worked. The weird thing is the dependency report doesn't show quarkus having any grpc transitive dep. But adding the following to
dependencyManagement
portion of maven pom file fixed it:
Copy code
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-core</artifactId>
  <version>1.63.0</version>
</dependency>
<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java</artifactId>
  <version>4.26.1</version>
</dependency>