Table of Contents

Interface ICarrotClient

Namespace
CarrotMQ.Core
Assembly
CarrotMQ.Core.dll

Represents a messaging client designed 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 interface ICarrotClient

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).

Task PublishAsync<TEvent>(ICustomRoutingEvent<TEvent> @event, Context? context = null, MessageProperties? messageProperties = null, CancellationToken cancellationToken = default) where TEvent : ICustomRoutingEvent<TEvent>

Parameters

event ICustomRoutingEvent<TEvent>

The event instance to be published.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TEvent

The 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 by cancellationToken.

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).

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

event IEvent<TEvent, TExchangeEndPoint>

The event instance to be published.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties. If not specified Default is used.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TEvent

The type of the event to be published.

TExchangeEndPoint

The 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 by cancellationToken.

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).

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

command ICommand<TCommand, TResponse, TEndPointDefinition>

The command instance to be sent.

replyEndPoint ReplyEndPointBase

The optional reply endpoint for the command.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties. If not specified Default is used.

correlationId Guid?

The optional correlation ID for the operation.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TCommand

The type of the command to be sent.

TResponse

The type of the expected response.

TEndPointDefinition

The 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 by cancellationToken.

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).

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

query IQuery<TQuery, TResponse, TEndPointDefinition>

The query instance to be sent.

replyEndPoint ReplyEndPointBase

The reply endpoint for the query.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties. If not specified Default is used.

correlationId Guid?

The optional correlation ID for the operation.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

TQuery

The type of the query to be sent.

TResponse

The type of the expected response.

TEndPointDefinition

The 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 by cancellationToken.

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).

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

command ICommand<TCommand, TResponse, TEndPointDefinition>

The command instance to be sent.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties. If not specified Default is used and TTL set to 5000.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task<CarrotResponse<TCommand, TResponse>>

The reply to the command.

Type Parameters

TCommand

The type of the command to be sent.

TResponse

The type of the expected response.

TEndPointDefinition

The 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 by cancellationToken.

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).

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

query IQuery<TQuery, TResponse, TEndPointDefinition>

The query instance to be sent.

context Context

The optional context for the operation.

messageProperties MessageProperties?

The optional MessageProperties. If not specified Default is used and TTL set to 5000.

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task<CarrotResponse<TQuery, TResponse>>

The reply to the query.

Type Parameters

TQuery

The type of the query to be sent.

TResponse

The type of the expected response.

TEndPointDefinition

The 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 by cancellationToken.

RetryLimitExceededException

Thrown if the message could not published within the defined amount of retries