I have gateway project that send data by in MassTransit, and wait to get the response.
I need to add custom header to the request and get it in the consumer
here the gateway code:
private readonly IRequestClient<TokenContracts.FullRequest<REQ>> _Client;
public GWController(IRequestClient<TokenContracts.FullRequest<REQ>> submitTokenRequestClient)
{
_Client = submitTokenRequestClient;
}
[HttpPost("REQ")]
public async Task<IActionResult> Validate(TokenContracts.FullRequest<REQ> model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
var response = await _Client.GetResponse<TokenContracts.FullResponse<Res>>(model);
if (response?.Message?.Msg?.RcType != 1)
return BadRequest(response.Message);
return Accepted(response.Message);
}
catch (System.Exception ex)
{
return Problem(ex.Message);
}
}
How can I send the header and get it in the consumer?
Here is the consumer:
public async Task Consume(ConsumeContext<FullRequest<REQ>> context)
{
try
{
var correlationId = context.Headers.Get<Guid>("aa");
var req = Encoding.UTF8.GetString((byte[])context.ReceiveContext.GetBody());
var res = await mediator.Send(context.Message.appData);
await context.RespondAsync<FullResponse<RES>>(res);
return;
}
catch (BadRequestException ex)
{
}
}