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

Programmatic subscription with minimal API not working as expected with raw messages #1454

Open
rochabr opened this issue Feb 5, 2025 · 0 comments
Labels
area/client/pubsub kind/bug Something isn't working

Comments

@rochabr
Copy link

rochabr commented Feb 5, 2025

Expected Behavior

In theory, programmatically mapping a subscription route should work like the following:

// Map the route for both HTTP and Dapr
app.MapPost("/messages", handler)
   .WithTopic("redis-pubsub", "employeemessage", true)  // This enables Dapr subscription - true == raw messages
   .WithName("ProcessMessage")
   .WithTags("Messages")
   .WithOpenApi();

Actual Behavior

However in this case, the subscriber is not able to parse the message as it is expecting an octet-stream.

The code above returns:

== APP == info: Subscriber.API.Modules.MessagesModule[0]
== APP ==       {"data_base64":"eyJpZCI6MiwibmFtZSI6IkphbmUgRG9lIn0=","datacontenttype":"application/octet-stream","id":"f5f38e3a-f07d-4d57-8699-535e80e62fd6","pubsubname":"redis-pubsub","source":"Dapr","specversion":"1.0","topic":"employeemessage","type":"com.dapr.event.sent"}

Steps to Reproduce the Problem

Follow the instructions here: https://github.com/rochabr/mediatr-dapr-sample and make the necessary changes within MessageModule.cs and Program.cs In the Subscriber.API project.

To bypass the issue, I had to map the subscription endpoint explicitly:

//Dapr subscription endpoint - using absolute path to avoid conflicts
app.MapGet("/dapr/subscribe", (HttpContext context) =>
{
    var subscriptions = new[]
    {
        new
        {
            pubsubname = "redis-pubsub",
            topic = "employeemessage",
            route = "/messages",
            metadata = new Dictionary<string, string>
            {
                { "isRawPayload", "true" },
                { "content-type", "application/json" }
            }
        }
    };
    return Results.Ok(subscriptions);
})
.ExcludeFromDescription();  // This excludes it from OpenAPI/Swagger


//Message handler endpoint
app.MapPost("/messages", employeeHandler)
   .WithTags("Messages");
@rochabr rochabr added the kind/bug Something isn't working label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client/pubsub kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants