I tried to publish a message with metadata using DAPR.
The producer is like this:
public class Message
{
[JsonPropertyName("messageId")]
public Int32 MessageId { get; set; }
[JsonPropertyName("tenantId")]
public Int32 TenantId { get; set; }
public Message(int messageId, int tenantId)
{
MessageId = messageId;
TenantId = tenantId;
}
}
using var client = new DaprClientBuilder().Build();
var tenantId = Rnd.Next(0, _test.DifferentTenantIds)+1;
var metaData = new Dictionary<string, string>()
{
{ "SessionId",$"TENANT.{tenantId}" }
};
var message = new Message(1, tenantId);
var status = client.PublishEventAsync("PRODUCT", "EVENT1", message, metaData, CancellationToken.None).Status;
The sending seems correct, the message arrives to the receiver side, but the sessionId is not there where I expect - the sessionId is empty, and debugging I can see the the job has only the commont attributes: id, source, type, datacontenttype, dataschema, subject and time:
using CloudNative.CloudEvents;
app.MapGet("/dapr/subscribe", ([FromServices] ILogger logger) =>
{
var sub1 = new DaprSubscription("PRODUCT", "EVENT1", "productEvent1");
logger.LogInformation("Dapr pub/sub is subscribed to {0}", JsonSerializer.Serialize(sub1));
var result = Results.Json(new[] { sub1 });
return result;
});
app.MapPost("/productEvent1", async ([FromBody] CloudEvent job, [FromServices] ILogger<ProductManagementApi> logger) =>
{
var sessionId = job.GetAttribute("SessionId");
logger.LogInformation($"* received a message A with sessionId={sessionId}");
return Results.Ok();
}
The example uses basic DAPR configuration using Docker on local machine, REDIS as message queue provider.
Any advice?