Ozkan
Ozkan

Reputation: 4170

Difference between CreateRequestClient and CreatePublishRequestClient

In a Request Response pattern using MassTransit with RabbitMQ, I'm trying to create a request client. But when doing some research on the internet i saw two possibilities:

CreateRequestClient and CreatePublishRequestClient

Does someone know what's the difference between those two and when to use them?

see below for the methods:

  public static class RequestClientExtensions
  {
    public static IRequestClient<TRequest, TResponse> CreateRequestClient<TRequest, TResponse>(this IBus bus, Uri address, TimeSpan timeout, TimeSpan? ttl = null, Action<SendContext<TRequest>> callback = null) where TRequest : class where TResponse : class
    {
      return (IRequestClient<TRequest, TResponse>) new MessageRequestClient<TRequest, TResponse>(bus, address, timeout, ttl, callback);
    }

    public static IRequestClient<TRequest, TResponse> CreatePublishRequestClient<TRequest, TResponse>(this IBus bus, TimeSpan timeout, TimeSpan? ttl = null, Action<SendContext<TRequest>> callback = null) where TRequest : class where TResponse : class
    {
      return (IRequestClient<TRequest, TResponse>) new PublishRequestClient<TRequest, TResponse>(bus, timeout, ttl, callback);
    }
  }

Upvotes: 0

Views: 1370

Answers (1)

Alexey Zimarev
Alexey Zimarev

Reputation: 19610

Well, the set of arguments explain the difference. This is the same difference as we have between Send and Publish. Publish uses fan-out exchange and Send delivers to a specific exchange only.

Normal RequestClient will do Send under the hood and needs the receiver address.

PublishRequestClient does not need any address since it will just publish the message and hope that someone will reply to it.

If you want to know more about Send vs Publish difference, you can check this blog post.

Upvotes: 1

Related Questions