0

How to send a message of type 'Any' using grpcurl?

I have this proto:

message MyRequest {
  string request_id = 1;
  repeated google.protobuf.Any payload = 2;
}

I am sending this request:

{
   "request_id":"1",
   "payload":[
      {
         "@type":"type.googleapis.com/com.my.type.Payload",
         "id":"12345",
         "message": "Hello",
      }
   ]
}

grpcurl -plaintext -d '{"request_id": "1", "payload": [{"@type": "type.googleapis.com/com.my.type.Payload", "id": "12345", "message": "Hello"}]}' localhost:1000 com.my.service.ServiceName/Method

but I get an error: Error invoking method "com.my.service.ServiceName/Method": error getting request data: unknown message type "com.my.type.Payload"

The server is a Spring Boot project in Kotlin, so I added a bean

@Bean
fun protobufJsonFormatHttpMessageConverter(): ProtobufHttpMessageConverter? {
    val typeRegistry: JsonFormat.TypeRegistry = JsonFormat.TypeRegistry.newBuilder()
        .add(com.my.type.Payload.getDescriptor())
        .build()

    val printer = JsonFormat.printer().usingTypeRegistry(typeRegistry)
    return ProtobufJsonFormatHttpMessageConverter(JsonFormat.parser(), printer)
}

But it didn't help. How to fix it?

Olga
  • 309
  • 4
  • 16
  • I suspect -- but don't know -- that you need to encode `payload` as a `[]byte` rather than treat is as an encapsulated message. Unfortunately, I don't know how you'd encode it but you may be able to get away with base64. – DazWilkin Jun 30 '21 at 21:33
  • It may be worth submitting an issue to the `gRPCurl` repo and asking there: https://github.com/fullstorydev/grpcurl/issues – DazWilkin Jun 30 '21 at 21:34
  • Thank you, found the same issue there: https://github.com/fullstorydev/grpcurl/issues/193 – Olga Jun 30 '21 at 22:19
  • You're welcome. I tried searching for issues there for you and did not find that one! – DazWilkin Jun 30 '21 at 22:32

0 Answers0