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
rabbitMqSettingsIOptions<RabbitMqSettings>loggerILogger<PublisherService>
Methods
CreateQueue(string)
Creates a new queue with the specified name.
public Task<bool> CreateQueue(string queueName)
Parameters
queueNamestringThe 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
objobjectThe object to serialize and send to the queue.
queueNamestringThe name of the destination queue.
Returns
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
msgstringThe message payload to send to the queue.
queueNamestringThe name of the target queue to which the message will be sent.
Returns
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
objobjectThe message object expected to be a
Message<Error>. If it is not, the method returnsfalsewithout sending anything.queueNamestringThe 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
truewhen the error message is successfully sent, andfalsewhen the bus is null, the object is not aMessage<Error>, or an exception is raised while sending.