Class CarrotClient
Implementation of the ICarrotClient interface for publishing events and sending commands/queries. When paired with our CarrotMQ.RabbitMQ NuGet package, this client enables the seamless transmission of messages over RabbitMQ.
public sealed class CarrotClient : ICarrotClient
- Inheritance
-
CarrotClient
- Implements
- Inherited Members
Constructors
CarrotClient(ITransport, ICarrotSerializer, ICarrotMessageBuilder)
Initializes a new instance of the CarrotClient class.
public CarrotClient(ITransport transport, ICarrotSerializer serializer, ICarrotMessageBuilder messageBuilder)
Parameters
transportITransportThe transport mechanism for message exchange.
serializerICarrotSerializerThe serializer for message payloads.
messageBuilderICarrotMessageBuilderThe message builder used to convert typed messages into CarrotMessages
Methods
PublishAsync<TEvent>(ICustomRoutingEvent<TEvent>, Context?, MessageProperties?, CancellationToken)
Publishes an event ICustomRoutingEvent<TEvent> with a customizable Exchange and RoutingKey Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific implementations).
public Task PublishAsync<TEvent>(ICustomRoutingEvent<TEvent> @event, Context? context = null, MessageProperties? messageProperties = null, CancellationToken cancellationToken = default) where TEvent : ICustomRoutingEvent<TEvent>
Parameters
eventICustomRoutingEvent<TEvent>The event instance to be published.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TEventThe type of the event to be published.
Exceptions
- ArgumentException
Thrown if the provided event has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries
PublishAsync<TEvent, TExchangeEndPoint>(IEvent<TEvent, TExchangeEndPoint>, Context?, MessageProperties?, CancellationToken)
Publishes an event IEvent<TEvent, TExchangeEndPoint>. Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific implementations).
public Task PublishAsync<TEvent, TExchangeEndPoint>(IEvent<TEvent, TExchangeEndPoint> @event, Context? context = null, MessageProperties? messageProperties = null, CancellationToken cancellationToken = default) where TEvent : IEvent<TEvent, TExchangeEndPoint> where TExchangeEndPoint : ExchangeEndPoint, new()
Parameters
eventIEvent<TEvent, TExchangeEndPoint>The event instance to be published.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties. If not specified Default is used.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TEventThe type of the event to be published.
TExchangeEndPointThe type of the exchange endpoint associated with the event.
Exceptions
- ArgumentException
Thrown if the provided event has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries
SendAsync<TCommand, TResponse, TEndPointDefinition>(ICommand<TCommand, TResponse, TEndPointDefinition>, ReplyEndPointBase?, Context?, MessageProperties?, Guid?, CancellationToken)
Sends a command ICommand<TCommand, TResponse, TEndPointDefinition>.
Depending on replyEndPoint a reply is sent asynchronously or not at all.
Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific
implementations).
public Task SendAsync<TCommand, TResponse, TEndPointDefinition>(ICommand<TCommand, TResponse, TEndPointDefinition> command, ReplyEndPointBase? replyEndPoint = null, Context? context = null, MessageProperties? messageProperties = null, Guid? correlationId = null, CancellationToken cancellationToken = default) where TCommand : ICommand<TCommand, TResponse, TEndPointDefinition> where TResponse : class where TEndPointDefinition : EndPointBase, new()
Parameters
commandICommand<TCommand, TResponse, TEndPointDefinition>The command instance to be sent.
replyEndPointReplyEndPointBaseThe optional reply endpoint for the command.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties. If not specified Default is used.
correlationIdGuid?The optional correlation ID for the operation.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TCommandThe type of the command to be sent.
TResponseThe type of the expected response.
TEndPointDefinitionThe type of the endpoint definition associated with the command.
Exceptions
- ArgumentException
Thrown if the provided command has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries
SendAsync<TQuery, TResponse, TEndPointDefinition>(IQuery<TQuery, TResponse, TEndPointDefinition>, ReplyEndPointBase, Context?, MessageProperties?, Guid?, CancellationToken)
Sends a query IQuery<TQuery, TResponse, TEndPointDefinition>.
The reply is sent asynchronously to replyEndPoint.
Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific
implementations).
public Task SendAsync<TQuery, TResponse, TEndPointDefinition>(IQuery<TQuery, TResponse, TEndPointDefinition> query, ReplyEndPointBase replyEndPoint, Context? context = null, MessageProperties? messageProperties = null, Guid? correlationId = null, CancellationToken cancellationToken = default) where TQuery : IQuery<TQuery, TResponse, TEndPointDefinition> where TResponse : class where TEndPointDefinition : EndPointBase, new()
Parameters
queryIQuery<TQuery, TResponse, TEndPointDefinition>The query instance to be sent.
replyEndPointReplyEndPointBaseThe reply endpoint for the query.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties. If not specified Default is used.
correlationIdGuid?The optional correlation ID for the operation.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task representing the asynchronous operation.
Type Parameters
TQueryThe type of the query to be sent.
TResponseThe type of the expected response.
TEndPointDefinitionThe type of the endpoint definition associated with the query.
Exceptions
- ArgumentException
Thrown if the provided query has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries
SendReceiveAsync<TCommand, TResponse, TEndPointDefinition>(ICommand<TCommand, TResponse, TEndPointDefinition>, Context?, MessageProperties?, CancellationToken)
Sends a command ICommand<TCommand, TResponse, TEndPointDefinition> and returns the reply. Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific implementations).
public Task<CarrotResponse<TCommand, TResponse>> SendReceiveAsync<TCommand, TResponse, TEndPointDefinition>(ICommand<TCommand, TResponse, TEndPointDefinition> command, Context? context = null, MessageProperties? messageProperties = null, CancellationToken cancellationToken = default) where TCommand : ICommand<TCommand, TResponse, TEndPointDefinition> where TResponse : class where TEndPointDefinition : EndPointBase, new()
Parameters
commandICommand<TCommand, TResponse, TEndPointDefinition>The command instance to be sent.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties. If not specified Default is used and TTL set to 5000.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task<CarrotResponse<TCommand, TResponse>>
The reply to the command.
Type Parameters
TCommandThe type of the command to be sent.
TResponseThe type of the expected response.
TEndPointDefinitionThe type of the endpoint definition associated with the command.
Exceptions
- ArgumentException
Thrown if the provided command has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries
SendReceiveAsync<TQuery, TResponse, TEndPointDefinition>(IQuery<TQuery, TResponse, TEndPointDefinition>, Context?, MessageProperties?, CancellationToken)
Sends a query IQuery<TQuery, TResponse, TEndPointDefinition> and returns the reply. Note: This method may also throw exceptions from underlying system or library code (serializers or transport specific implementations).
public Task<CarrotResponse<TQuery, TResponse>> SendReceiveAsync<TQuery, TResponse, TEndPointDefinition>(IQuery<TQuery, TResponse, TEndPointDefinition> query, Context? context = null, MessageProperties? messageProperties = null, CancellationToken cancellationToken = default) where TQuery : IQuery<TQuery, TResponse, TEndPointDefinition> where TResponse : class where TEndPointDefinition : EndPointBase, new()
Parameters
queryIQuery<TQuery, TResponse, TEndPointDefinition>The query instance to be sent.
contextContextThe optional context for the operation.
messagePropertiesMessageProperties?The optional MessageProperties. If not specified Default is used and TTL set to 5000.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task<CarrotResponse<TQuery, TResponse>>
The reply to the query.
Type Parameters
TQueryThe type of the query to be sent.
TResponseThe type of the expected response.
TEndPointDefinitionThe type of the endpoint definition associated with the query.
Exceptions
- ArgumentException
Thrown if the provided query has invalid properties.
- OperationCanceledException
Thrown if the message could not published in time (based on message ttl in
context"/> Ttl) or the operation has been canceled bycancellationToken.- RetryLimitExceededException
Thrown if the message could not published within the defined amount of retries