On Thu, Sep 8, 2016 at 3:19 AM, Francesco Persico <
francescopers...@gmail.com> wrote:

> I am using protobuf as serialization to send DomainEvent(s) from one
> microservice to another one.
> So from one side i am sending messages to a Kafka topic (messages are
> protobuf serialized DomainEvent like UserCreated(...) or UserUpdated(...))
> and it works good.
> My .proto file is simple like
>
> message UserCreated {
> ...
> }
>
> message UserUpdated {
> ...
> }
>

Instead of sending multiple different message types, you can just send one
message type with an oneof field in it:

message Event {
  oneof event {
    UserCreated user_created_event = 1;
    UseUpdated user_updated_event = 2;
  }
}

and then in the receiving side you can check the oneof to see which event
it actually is.


>
> The problem is that when reading from the other side i need to know the
> specific type/class of the message like UserCreated(...) vs
> UserUpdated(...).
> How can i know if the bytes received from Kafka are a UserCreated message
> or a UserUpdated message?
> Do i need to create the .proto file in a different way? Do i need to store
> the message type somewhere in the .proto file?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to