Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Protobuf #1991

Closed
MichalNemec opened this issue May 6, 2024 · 4 comments
Closed

[FR] Protobuf #1991

MichalNemec opened this issue May 6, 2024 · 4 comments
Labels
feature-request New feature or request

Comments

@MichalNemec
Copy link

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

@MichalNemec MichalNemec added the feature-request New feature or request label May 6, 2024
@simonthum
Copy link
Contributor

simonthum commented May 10, 2024

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.

@rido-min
Copy link
Member

this sample shows how to use protobuf with MQTTnet

https://github.com/Azure-Samples/MqttApplicationSamples/tree/main/scenarios/command/dotnet

@SeppPenner
Copy link
Collaborator

You can also take a look at https://github.com/SeppPenner/SparkplugNet which uses ProtoBuf messages over MQTT.

@chkr1011
Copy link
Collaborator

I assume the question is answered. If not, please reopen the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants