当我发布这样的事件时,有没有办法在saga中访问标题?
await busControl.Publish<IOrderCreated>(new
{
OrderId = dto.Id
}, context =>
{
context.Headers.Set(LogConstansts.Common.OperationId,Guid.Parse(values.Single()).ToString());
context.Headers.Set(LogConstansts.QueueMessageHeaderNames.Publisher, Request.RequestUri.AbsoluteUri);
});
然后在传奇
Initially(
When(OrderCreated)
.Then(context =>
{
//get headers somehow?
context.Instance.OrderId = context.Data.OrderId;
})
答案 0 :(得分:3)
是的,您可以通过从行为上下文中获取使用上下文有效内容来访问它:
Initially(
When(OrderCreated)
.Then(context =>
{
ConsumeContext<IOrderCreated> c;
if (context.TryGetPayload(out c))
{
c.Headers.Get<string>("myheader");
// do something
}
context.Instance.OrderId = context.Data.OrderId;
})