wvlet / airframe

Essential Building Blocks for Scala
https://wvlet.org/airframe
Apache License 2.0
632 stars 66 forks source link

examples/rpc-examples/hello-rpc/ causes a compilation error #1319

Closed NomadBlacky closed 4 years ago

NomadBlacky commented 4 years ago

I tried the example project of examples/rpc-examples/hello-rpc/, but I met a compilation error.

source code

logs

$ sbt
[info] welcome to sbt 1.4.0 (AdoptOpenJDK Java 1.8.0_252)
[info] loading settings for project global-plugins from sbt-updates.sbt ...
[info] loading global plugins from /home/nomadblacky/.sbt/1.0/plugins
[info] loading settings for project airframe-hello-rpc-build from plugins.sbt ...
[info] loading project definition from /home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/project
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] loading settings for project greeter from build.sbt ...
[info] set current project to greeter (in build file:/home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/)
[info]
[info] Here are some highlights of this release:
[info]   - Build server protocol (BSP) support
[info]   - sbtn: a native thin client for sbt
[info]   - VirtualFile + RemoteCache: caches build artifacts across different machines
[info]   - ThisBuild / versionScheme to take the guessing out of eviction warning
[info] See http://eed3si9n.com/sbt-1.4.0 for full release notes.
[info] Hide the banner for this release by running `skipBanner`.
[info] sbt server started at local:///home/nomadblacky/.sbt/1.0/server/5bd55ad33ab16ecbace2/sock
sbt:greeter> compile
2020-10-17 23:21:31.769+0900  info [AirframeHttpPlugin] Extracting airframe-http 20.8.0 package to /home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/target/scala-2.12/airframe/20.8.0/local  - (AirframeHttpPlugin.scala:141)
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
2020-10-17 23:21:33.330+0900 debug [HttpCodeGenerator] HttpClientGeneratorConfig(greeter.api,wvlet.airframe.http.codegen.client.SyncClient$@e36bb2a,greeter.api)  - (HttpCodeGenerator.scala:149)
2020-10-17 23:21:33.341+0900  info [HttpCodeGenerator] Target API packages: greeter.api  - (HttpCodeGenerator.scala:129)
2020-10-17 23:21:33.376+0900  info [HttpCodeGenerator]
Router for package greeter.api:
- Router[659efc34]  - (HttpCodeGenerator.scala:161)
2020-10-17 23:21:33.376+0900  info [HttpCodeGenerator] Generating a sync client code: greeter/api/ServiceSyncClient.scala  - (HttpCodeGenerator.scala:162)
2020-10-17 23:21:33.381+0900 debug [HttpCodeGenerator]
/**
 * === DO NOT EDIT THIS FILE ===
 * This code is generated by sbt-airframe plugin.
 */
package greeter.api

import wvlet.airframe.http._

class ServiceSyncClient[Req, Resp](private val client: HttpSyncClient[Req, Resp]) extends AutoCloseable {
  override def close(): Unit = { client.close() }
  def getClient: HttpSyncClient[Req, Resp] = client

}
  - (HttpCodeGenerator.scala:74)
2020-10-17 23:21:33.383+0900 debug [HttpCodeGenerator] HttpClientGeneratorConfig(greeter.api,wvlet.airframe.http.codegen.client.GrpcClient$@3088660d,greeter.api)  - (HttpCodeGenerator.scala:149)
2020-10-17 23:21:33.383+0900  info [HttpCodeGenerator] Target API packages: greeter.api  - (HttpCodeGenerator.scala:129)
2020-10-17 23:21:33.399+0900  info [HttpCodeGenerator]
Router for package greeter.api:
- Router[659efc34]  - (HttpCodeGenerator.scala:161)
2020-10-17 23:21:33.399+0900  info [HttpCodeGenerator] Generating a grpc client code: greeter/api/ServiceGrpc.scala  - (HttpCodeGenerator.scala:162)
2020-10-17 23:21:33.402+0900 debug [HttpCodeGenerator]
/**
 * === DO NOT EDIT THIS FILE ===
 * This code is generated by sbt-airframe plugin.
 */
package greeter.api

import wvlet.airframe.http._

object ServiceGrpc {
  import wvlet.airframe.msgpack.spi.MsgPack
  import wvlet.airframe.codec.{MessageCodec, MessageCodecFactory}
  import wvlet.airframe.http.grpc.GrpcServiceBuilder.{RPCRequestMarshaller, RPCResponseMarshaller}

  private def newDescriptorBuilder(
    fullMethodName:String,
    methodType:io.grpc.MethodDescriptor.MethodType
  ) : io.grpc.MethodDescriptor.Builder[MsgPack, Any] = {
    io.grpc.MethodDescriptor.newBuilder[MsgPack, Any]()
      .setType(methodType)
      .setFullMethodName(fullMethodName)
      .setRequestMarshaller(RPCRequestMarshaller)
  }

  def newSyncClient(
    channel: io.grpc.Channel,
    callOptions: io.grpc.CallOptions = io.grpc.CallOptions.DEFAULT,
    codecFactory: MessageCodecFactory = MessageCodecFactory.defaultFactoryForJSON
  ): SyncClient = new SyncClient(channel, callOptions, codecFactory)

  class SyncClient(
    val channel: io.grpc.Channel,
    callOptions: io.grpc.CallOptions = io.grpc.CallOptions.DEFAULT,
    codecFactory: MessageCodecFactory = MessageCodecFactory.defaultFactoryForJSON
  ) extends io.grpc.stub.AbstractBlockingStub[SyncClient](channel, callOptions) with java.lang.AutoCloseable {

    override protected def build(channel: io.grpc.Channel, callOptions: io.grpc.CallOptions): SyncClient = {
      new SyncClient(channel, callOptions, codecFactory)
    }

    override def close(): Unit = {
      channel match {
        case m: io.grpc.ManagedChannel => m.shutdownNow()
        case _ =>
      }
    }

  }

  def newAsyncClient(
    channel: io.grpc.Channel,
    callOptions: io.grpc.CallOptions = io.grpc.CallOptions.DEFAULT,
    codecFactory: MessageCodecFactory = MessageCodecFactory.defaultFactoryForJSON
  ): AsyncClient = new AsyncClient(channel, callOptions, codecFactory)

  class AsyncClient(
    val channel: io.grpc.Channel,
    callOptions: io.grpc.CallOptions = io.grpc.CallOptions.DEFAULT,
    codecFactory: MessageCodecFactory = MessageCodecFactory.defaultFactoryForJSON
  ) extends io.grpc.stub.AbstractAsyncStub[AsyncClient](channel, callOptions) with java.lang.AutoCloseable {

    override protected def build(channel: io.grpc.Channel, callOptions: io.grpc.CallOptions): AsyncClient = {
      new AsyncClient(channel, callOptions, codecFactory)
    }

    override def close(): Unit = {
      channel match {
        case m: io.grpc.ManagedChannel => m.shutdownNow()
        case _ =>
      }
    }

  }
}
  - (HttpCodeGenerator.scala:74)
[info] compiling 4 Scala sources to /home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/target/scala-2.12/classes ...
[error] /home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/src/main/scala/greeter/GreeterMain.scala:67:31: value GreeterApi is not a member of greeter.api.ServiceSyncClient[com.twitter.finagle.http.Request,com.twitter.finagle.http.Response]
[error]         val response = client.GreeterApi.hello(s"RPC${i}")
[error]                               ^
[error] /home/nomadblacky/ghq/github.com/NomadBlacky/airframe-hello-rpc/src/main/scala/greeter/GreeterMain.scala:93:29: value GreeterApi is not a member of greeter.api.ServiceGrpc.SyncClient
[error]       val response = client.GreeterApi.hello(s"RPC${i}")
[error]                             ^
[error] two errors found
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 4 s, completed 2020/10/17 23:21:35
xerial commented 4 years ago

Thanks. Fixed in #1322

NomadBlacky commented 4 years ago

Thank you for fixing the issue!

BTW, I tried the gRPC example in README, but the gRPC client thrown a NoSuchMethodError. I noticed that it was working with JDK8 on my environment, so I switched to JDK11 and It worked fine.

Does Airframe support JDK11 or later?

JVM

$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.252-b09, mixed mode)

Server

$ ./target/pack/bin/greeter-main grpcServer
2020-10-21 04:42:53.294+0900  info [LifeCycleManager] [session:65bb9029] Starting a new lifecycle ...  - (LifeCycleManager.scala:284)
2020-10-21 04:42:53.307+0900  info [LifeCycleManager] [session:65bb9029] ======== STARTED ========  - (LifeCycleManager.scala:288)
2020-10-21 04:42:53.462+0900  info [GrpcServer] Starting gRPC server default at localhost:8080  - (GrpcServer.scala:107)
2020-10-21 04:43:06.309+0900  info [DISupport] Received a request from: RPC0  - (GreeterApi.scala:9)

Client

$ ./target/pack/bin/greeter-main grpcClient
Exception in thread "main" io.grpc.StatusRuntimeException: CANCELLED: Failed to read message.
        at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262)
        at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243)
        at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156)
        at greeter.api.ServiceGrpc$SyncClient$GreeterApi$.hello(ServiceGrpc.scala:71)
        at greeter.GreeterMain.$anonfun$grpcClient$1(GreeterMain.scala:93)
        at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:158)
        at greeter.GreeterMain.grpcClient(GreeterMain.scala:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at wvlet.airframe.surface.reflect.ReflectMethodSurface.call(ReflectMethodSurface.scala:47)
        at wvlet.airframe.launcher.CommandLauncher.$anonfun$execute$8(Launcher.scala:372)
        at scala.Option.map(Option.scala:230)
        at wvlet.airframe.launcher.CommandLauncher.execute(Launcher.scala:370)
        at wvlet.airframe.launcher.CommandLauncher.execute(Launcher.scala:336)
        at wvlet.airframe.launcher.Launcher.execute(Launcher.scala:160)
        at greeter.GreeterMain$.main(GreeterMain.scala:29)
        at greeter.GreeterMain.main(GreeterMain.scala)
Caused by: java.lang.NoSuchMethodError: java.io.InputStream.readAllBytes()[B
        at wvlet.airframe.http.grpc.GrpcServiceBuilder$RPCResponseMarshaller.parse(GrpcServiceBuilder.scala:140)
        at io.grpc.MethodDescriptor.parseResponse(MethodDescriptor.java:273)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:655)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:640)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        at io.grpc.stub.ClientCalls$ThreadlessExecutor.waitAndDrain(ClientCalls.java:740)
        at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:149)
        ... 16 more
xerial commented 4 years ago

@NomadBlacky Thanks. Filed a bug ticket in #1329 We usually use JDK11, and are trying to stop the support for JDK8 and Scala 2.11 soon, but this error can be solved by using another method.