Open laglangyue opened 2 months ago
I went to learn about GRPC, header=>message=>trailers We stored the header and future [trailers] through GrpcResponseMetadata We have completed the promise [GrpcResponseMetada] in onHeader, so we are unable to assign a value to the trainers, So the original author defined another Promise [trailers] When on Hedaer, GrpcResponseMetadata is in a semi completed state OnClose is the final state
I think this FIXME may not be necessary, but there is a lot of repetitive code about GrpcResponseMetada, which can be constructed using a builder pattern to create GrpcResponseMetada, with Header, with Message, with Close (with Trailers)
I have tried writing some code locally, but I still need some deeper exploration
class GrpcResponseMetadataImpl(
grpcHeaders: io.grpc.Metadata, trailersPromise: Promise[io.grpc.Metadata]) extends GrpcResponseMetadata {
override def headers: pekko.grpc.scaladsl.Metadata =
MetadataImpl.scalaMetadataFromGoogleGrpcMetadata(grpcHeaders)
override def getHeaders(): pekko.grpc.javadsl.Metadata =
MetadataImpl.javaMetadataFromGoogleGrpcMetadata(grpcHeaders)
override def trailers: Future[pekko.grpc.scaladsl.Metadata] =
trailersPromise.future.map(MetadataImpl.scalaMetadataFromGoogleGrpcMetadata)(ExecutionContexts.parasitic)
override def getTrailers(): CompletionStage[pekko.grpc.javadsl.Metadata] =
trailersPromise.future.map(MetadataImpl.javaMetadataFromGoogleGrpcMetadata)(ExecutionContexts.parasitic)
.asJava
}
source code https://github.com/apache/pekko-grpc/blob/83bdd04b1eb81c84153debab4a0945a6d52cc345/runtime/src/main/scala/org/apache/pekko/grpc/internal/PekkoNettyGrpcClientGraphStage.scala#L169-L176
I've submit a pr