subscribe to raw messages using .Net 6 and Dapr SDK
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
I am listening to MQTT provider using Dapr and it will be not be sending events in CloudEvents Format.
My intention is to be able to process messages as raw string and then do any conversion needed.
Currently my setup is as follows.
```
using Dapr.Client;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
//AddDapr() registers the Dapr integration with controllers.
builder.Services.AddControllers().AddDapr(
builder => builder.UseJsonSerializationOptions(
new System.Text.Json.JsonSerializerOptions()
{
PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true
}));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseRouting();
//registers the Cloud Events middleware in the request processing pipeline.
//This middleware will unwrap requests with Content-Type application/cloudevents+json so that model binding can access the event payload in the request body directly.
app.UseCloudEvents();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapSubscribeHandler();
endpoints.MapControllers();
});
```
In controller
[Topic("mqtt-pubsub", "testtopic", true)]
[HttpPost("ReceiveMessages")]
public ActionResult Process([FromBody] object message, [FromServices] DaprClient daprClient)
{
return message.ToString();
}
I am getting serialization errors.
time="2022-09-20T12:36:11.9731999+05:30" level=error msg="Failed processing MQTT message: testtopic#51: retriable error returned from app while processing pub/sub event 52f1b281-71e9-4bee-bacc-6a12b8c85841, topic: testtopic, body: {\"type\":\"https://tools.ietf.org/html/rfc7231#section-6.5.13\",\"title\":\"Unsupported Media Type\",\"status\":415,\"traceId\":\"00-93976651ea98962241a0dd3015eaca01-3db0514083fbbc9f-00\"}. status code returned: 415" app_id=order-processor instance=LIN22004804 scope=dapr.contrib type=log ver=1.8.4
If i do not put app.UseCloudEvents() then the subscription doesn't even work.
As you can see in controller, i have enabled raw messages. but how to get around this error if sender is not using cloudevents format at all? I would assume, it's a very common scenario!
Contributor guide
Assessment
This issue has not been assessed yet.