dapr / dapr/dotnet-sdk

Pub Sub: How to get meta-data about the subscription

Open
#1,042 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
2d 1h
Merged PRs (30d)
6

Description

For a project I'm working on, I would like to use Dapr to subscribe for messages that are being sent to an MQTT broker.
I've been looking at the documentation of how this can be done in .NET and it looks like the way to go is to create an ASP.NET application and create a controller method that acts as the subscriber, just like this:

```csharp
[Topic("mypubsub", "vesselmessages")]
[HttpPost("/vesselmessage")]
public async Task ReceiveMessages([FromBody] VesselMessage message)
{
_logger.LogInformation("message received: " + message.Message);

return Ok();
}
```

This works, but there are some things that I'd like to achieve, but I cannot find anything about that in the documentation. (Maybe I overlooked something):

- In fact, I want to subscribe to a wildcards of topics. so I've changed my topic subscription to:

```csharp
[Topic("mypubsub", "vesselmessages/#")]
```

And this works. I can see that if I send a message to topic `vesselmessages/test`, my asp.net application receives the message.

But now, when I receive a message, I want to know on which exact topic that message was received. So I'd like to be able to receive some meta-data about the message next to the message as well. How can I achieve that ?

- It looks like the way the .NET sdk works for pub/sub, is that it expects JSON formatted messages. However, I'd like to receive the raw payload in my subscription-handler in ASP.NET. I need this since the messages that I want to receive, are not always JSON formatted messages. I have devices that sent messages to the MQTT broker in a protobuf format. Therefore, I want to receive the raw payload so that I can deserialize them myself. Is that possible ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.