Using topic with request/response in masstransit

Viewed 2018

I'm using Masstransit dotnet core v6.3.1 with RabbitMQ v3. My case is sending request from api gateway to other services. Services consume by topics and Gateway using different topics per request. I'm trying to use request/response with masstransit. But requestClient declared exhange type to fanout. And I cant change the type. I want to use different routingKey per request with request/response. How can I do this?

I have used in gateway: (startup.cs)

cfg.AddRequestClient<ISimpleRequest>();

(Custom Controller)

await client.GetResponse<ISimpleResponse>(new { Data="test request"});

I have used in other services(startup):

cfg.ReceiveEndpoint("TestGateway", ep =>
{
    ep.Consumer(() => new SimpleConsumer(context));
});

(Custom Consumer)

await client.RespondAsync<ISimpleResponse>(new { Data="test response"});

Also I tried to declare exchange in rabbitmq first. After I created request from clientFactory with exchange Uri. But I had an error like " ...received 'fanout' but current is 'topic'."

1 Answers

There is a sample on using a direct exchange, topic exchanges are similar but support wildcard semantics. I'd suggest reviewing it to get more details on how to configure topology with RabbitMQ using MassTransit.

Sample

There is also documentation on how to setup routing keys with exchange types.

Related