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

Custom metadata not provided to subscriber #1438

Open
richaswr opened this issue Jan 7, 2025 · 1 comment
Open

Custom metadata not provided to subscriber #1438

richaswr opened this issue Jan 7, 2025 · 1 comment
Labels
area/client/pubsub kind/bug Something isn't working

Comments

@richaswr
Copy link

richaswr commented Jan 7, 2025

Expected Behavior

Custom metadata properties set for a message published using DaprClient are made available to subscribers of this message.

Actual Behavior

Custom metadata properties are not available from Http headers or otherwise.

Steps to Reproduce the Problem

  • My dapr components are set up with Azure Container Apps, so there may be a limitation I am unaware of
  • I am using Asp.net for this for the most part, with DaprClient used to publish and TopicAttribute to define subscriptions within the controllers.
  • Due to some complexity with our application, I use Terraform to actually set up the subscriptions, with disableEntityManagement set to true to prevent Dapr setting up the subscriptions itself (perhaps I've missed something key here)

With Azure Service Bus Topics, I can set custom metadata properties using the DaprClient on publish:

var metadata = new Dictionary<string, string>
{
    {"cloudevent.type", eventType},
    {"eventName", eventName}
};

//@event refers to a class object
await daprClient.PublishEventAsync("pubsubName", "topicName", @event, metadata, ct);

I have a controller with endpoints decorated using the TopicAttribute, like below:

[HttpPost]
[Route("handle")]
[Topic("pubsubName", "topicName")]
public async Task<Result> HandleMessageAsyncJsonDocument @event, [FromHeader(Name="eventName")]string eventName)
{
    logger.LogInformation($"EventName: {eventName}");
    var context = contextAccessor.HttpContext;
    if (context is null)
    {
        logger.LogInformation($"Could not retrieve HttpContext");
    }
    else
    {
        foreach(var header in context.Request.Headers)
        {
            logger.LogInformation($"Header: {header.Key} - {header.Value}");
        }
    }

    return Result.Error();
}

However, whether it's by the FromHeader property or the HttpContext itself, these custom properties, I believe referred to as ApplicationProperties in Azure Service Bus, are not made available.

Release Note

RELEASE NOTE:

@richaswr richaswr added the kind/bug Something isn't working label Jan 7, 2025
@BADF00D
Copy link

BADF00D commented Jan 22, 2025

Hi,
ist stumbled upon the same problem, but it seems to be more like a unexpected behavior, then a bug.

You should

  • Use at least version 1.15.0-rc01
  • correct the meta in the publisher:
var metadata = new Dictionary<string, string>
{
    {"cloudevent.type", eventType},
    {"cloudevent.eventName", eventName}
};
  • activated property forwarding in the subscription client for your property
app.UseCloudEvents(new CloudEventsMiddlewareOptions
{
    IncludedCloudEventPropertiesAsHeaders = ["event.eventName"]
});
  • correct the header name: [FromHeader(Name="cloudevent.eventname")]

This works on my machine when using the sdk quickstart example on commit 42a99c20a492d2d887d0e36f8f60a3a2d7e51950. I found that solution, because the topic on replace DAPR generated CloudEvent values uses the prefix cloudvent.. I can't explain why the prefix in the IncludedCloudEventPropertiesAsHeaders is event. Its also event. when using content based routing. I find that confusing, to say the least.

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

3 participants