Производитель такой: < /p>
Код: Выделить всё
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()
{
{ "SessionId",$"TENANT.{tenantId}" }
};
var message = new Message(1, tenantId);
var status = client.PublishEventAsync("PRODUCT", "EVENT1", message, metaData, CancellationToken.None).Status;
Код: Выделить всё
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 logger) =>
{
var sessionId = job.GetAttribute("SessionId");
logger.LogInformation($"* received a message A with sessionId={sessionId}");
return Results.Ok();
}
Подробнее здесь: https://stackoverflow.com/questions/771 ... e-metadata
Мобильная версия