0

I read all articles and forums for finding that, how to pass my http "Request-Id" to MassTarnsit Consumers.
all samples(this, this, and this) sent a new GUID. but this way don't suitable for my case.

althought, I have been passed my "Request-Id" to Consumers, with this follow code:

       var reqId = HttpContext.Request.Headers["Request-Id"].FirstOrDefault();
        await _publishEndpoint.Publish(new MyMessageContract
        {
            CallBackUrl = "CallBackUrl",
            ApiToken = "ApiToken1"
        }, ctx => ctx.CorrelationId = Guid.Parse(reqId));

but this block code don't satisfy me! because of I have to pass my http "Request-Id" in each publishing contract.

KoKo
  • 421
  • 1
  • 5
  • 21

1 Answers1

1

I'd recommend looking at the scoped filter sample, which uses middleware filters on publish, send, and consume to carry values from the HttpContext to the consumer.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • @thanks a lot. it's seems so good for my case. but another issue!: when set CorrelationId into header in 'publish filter' with this code: context.Headers.Set("CorrelationId", Guid.Parse(mycorrelationId));... then I got this exception: "masstransit The message was not confirmed: Value of type 'Guid' cannot appear as table value" – KoKo Apr 20 '21 at 09:07
  • For CorrelationId, you should use the built-in `context.CorrelationId = Guid.Parse(...)` instead of setting your own header value. – Chris Patterson Apr 20 '21 at 11:44
  • yes!. thanks a lot. you saved a part of my day. – KoKo Apr 20 '21 at 16:09