Pub Sub: How to get meta-data about the subscription
See original GitHub issueFor 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:
[Topic("mypubsub", "vesselmessages")]
[HttpPost("/vesselmessage")]
public async Task<ActionResult> 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:
[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 ?
Issue Analytics
- State:
- Created 7 months ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
As far as I know, dapr pub sub consumer assumes received message is in cloudevent format by default, as a message published by a dapr client is wrapped in a cloudevent unless specified otherwise.
Can you try to add rawPayload metadata while registering ListTopicSubscriptions, so received events will not be processed as cloudevents.
@fgheysels, glad it worked out for you.
@halspang, as fgheysels suggested documentation on this would be nice. I have put together a sample .net grpc service to consume messages published by non-dapr services. You can add it to dapr datnet-sdk examples if you like.
It utilizes RabbitMq as pubsub component, and even though it’s possible to get and process raw message, I couldn’t find a way to read message headers from either TopicEventRequest or ServerCallContext parameters. Is there a way to get message headers?