Table of Contents

Class PublisherService

Namespace
adas_core.Infrastructure.Services
Assembly
adas-core.Infrastructure.dll

Represents a service that implements the IPublisherService contract, providing the concrete implementation of the publishing operations defined by the interface.

public class PublisherService : IPublisherService
Inheritance
PublisherService
Implements
Inherited Members
Extension Methods

Constructors

PublisherService(IOptions<RabbitMqSettings>, ILogger<PublisherService>)

public PublisherService(IOptions<RabbitMqSettings> rabbitMqSettings, ILogger<PublisherService> logger)

Parameters

rabbitMqSettings IOptions<RabbitMqSettings>
logger ILogger<PublisherService>

Methods

CreateQueue(string)

Creates a new queue with the specified name.

public Task<bool> CreateQueue(string queueName)

Parameters

queueName string

The name of the queue to create.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result is true if the queue was created successfully; otherwise, false.

SendMessage(object, string)

Serializes the specified object to JSON and asynchronously sends it to the named queue.

public Task<bool> SendMessage(object obj, string queueName)

Parameters

obj object

The object to serialize and send to the queue.

queueName string

The name of the destination queue.

Returns

Task<bool>

A task that resolves to true if the message was sent successfully; otherwise, false.

SendMessage(string, string)

Sends a message to the specified queue using the configured bus. If the bus is not initialized or an error occurs, the operation is logged and false is returned.

public Task<bool> SendMessage(string msg, string queueName)

Parameters

msg string

The message payload to send to the queue.

queueName string

The name of the target queue to which the message will be sent.

Returns

Task<bool>

true if the message was sent successfully; otherwise, false.

SendMessageError(object, string)

Sends an error message to the specified queue. Validates that the bus instance is available and that the supplied object is a Message<Error>; returns false when either validation fails or when the send operation throws an exception.

public Task<bool> SendMessageError(object obj, string queueName)

Parameters

obj object

The message object expected to be a Message<Error>. If it is not, the method returns false without sending anything.

queueName string

The name of the queue to which the error message body will be sent. The queue is created if it does not already exist.

Returns

Task<bool>

A Task<TResult> that resolves to true when the error message is successfully sent, and false when the bus is null, the object is not a Message<Error>, or an exception is raised while sending.