Hi I have a data stream pipeline that works over "events". Those events are simple protocol buffer messages, say:
message OrderCoffee {
int32 id = 1;
}
message CancelOrder {
int32 id = 1;
}
A client then serialize/encode those messages and push them into a message broker (say Google Pub/Sub
). A subscriber consumes one message and tries to decode/deserialize (pseudocode):
decoded_message = OrderCoffe.decode(encoded_message)
decoded_message = CancelOrder.decode(encoded_message)
Which of those lines work? Both, at least in my Ruby code. I don't know if I have a conceptual misunderstanding about how to use protocol buffers or that is a ruby bug.
If that is the expected bahaviour, how can I know at runtime which message should I decode the received message?
EDIT:
Ok, the solution seems to be https://developers.google.com/protocol-buffers/docs/techniques?csw=1#self-description .
I couldn't understand though. Could someone provide an example of how to implement that in ruby?