Skip to content

.NET library that simplifies RabbitMQ usage and works with the Direct Exchange type.

License

Notifications You must be signed in to change notification settings

byerlikaya/Basic.RabbitMQ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic.RabbitMQ

.NET library that simplifies RabbitMQ usage and works with the Direct Exchange type.

GitHub Workflow Status (with event) Basic.RabbitMQ Nuget Basic.RabbitMQ Nuget

Quick Start

The usage of Basic.RabbitMQ is quite simple.

  1. Install Basic.RabbitMQ NuGet package from here.
PM> Install-Package Basic.RabbitMQ
  1. Add services.AddRabbitMQClient(Configuration);
builder.Services.AddRabbitMqClient(Configuration);
  1. Add the necessary information to the appsettings.json file.
   "MessageBrokerOptions": {
    "HostName": "",
    "UserName": "",
    "Password": "",
    "ExchangeName": "",
    "VirtualHost": "",
    "Port": -1
  }
  1. And start using it. And that's it.

Producer

[ApiController]
public class ProducerController(IMessageProducer messageProducer) : ControllerBase
{
    [HttpPost("/sendMessage")]
    public Task<IActionResult> SendMessage(string message)
    {
        messageProducer.SendMessage("Test_Queue", "Test_Routing_Key", message);
        return Task.FromResult<IActionResult>(Ok());
    }
}

Consumer

var messageConsumer = serviceProvider.GetService<IMessageConsumer>();

var channel = messageConsumer?.Channel("Test_Queue", "Test_Routing_Key");

var basicConsumer = messageConsumer?.GetConsumer(channel);

basicConsumer!.Received += BasicConsumerReceived;

Task BasicConsumerReceived(object sender, BasicDeliverEventArgs @event)
{
    var message = Encoding.UTF8.GetString(@event.Body.ToArray());

    Console.WriteLine($" [>] Received {message}");

    channel?.BasicAck(@event.DeliveryTag, false);

    await Task.Yield();
}

About

.NET library that simplifies RabbitMQ usage and works with the Direct Exchange type.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages