MQTTnet
MQTTnet copied to clipboard
[FR] Protobuf
Describe the feature request
Im using MQTTnet and we plan to use gRPC with protobuf and our broker (emqx) supports it. Would be nice to have that option with this library.
Which project is your feature request related to?
- Client
- ManagedClient
- Generic
Describe the solution you'd like
Be able to publish and subscribe to topic with specific protobuf, so we dont have to send just strings and have types straight away.
Describe alternatives you've considered
try to deserialize from string to protobuf/any model
Additional context
Flutter mqtt5_client supports protobuf and our dotnet backend uses MQTTnet library, but i dont see any option to publish and receive messages with protobuf
You should be able to do
mqttMessageBuilder
.WithPayload(protoObject.ToByteArray())
.WithContentType("application/vnd.google.protobuf")
and put that in an extension method if you prefer.
On the receiving side, just look for the content type and do
ExpectedType.Parser.ParseFrom(msg.Payload)
FWIW I would not expect the string encoding to work as you seem to assume.
this sample shows how to use protobuf with MQTTnet
https://github.com/Azure-Samples/MqttApplicationSamples/tree/main/scenarios/command/dotnet
You can also take a look at https://github.com/SeppPenner/SparkplugNet which uses ProtoBuf messages over MQTT.
I assume the question is answered. If not, please reopen the ticket.