0

I started working on Microservices. So I have made two Restful APIs.

  1. Organisations API ( GET, PUT, POST, DELETE )
  2. Customers API ( GET, PUT, POST, DELETE )

These two are separate APIs and hosted on different ports on my local IIS.

Now I want to consume them in my main application.

So the requirement is to call them only by Network connection.

I found that I need to use Rpc, gRpc or Kafka.

so, I have decided to use Rpc by using RabbitMq and EasyNetQ.

By this, I have configured rabbiqMq in docker and it is running successfully.

What I am not understanding is that in my Organisations and Customers API there are multiple actions. GET, PUT, POST, DELETE

So, Where I need to define the queue name for those method, so I can consume it in my main app by calling with some name. and it will directly call that method.

e.g.

var factory = new ConnectionFactory() { HostName = "localhost" };
        var connection = factory.CreateConnection();
        var channel = connection.CreateModel();
        var body = Encoding.UTF8.GetBytes(entity);
        channel.BasicPublish(exchange: "organisations", routingKey: "organisations.add", basicProperties: null, body: body);

Where in the organisations api, I will define this organisations.add, organisations.update, organisations.search ?

Can I add them dynamically through some mediator ? Or I need to add manually in the rabitmq ui .. to adding queue ?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ghazni
  • 826
  • 8
  • 16

1 Answers1

0

I usually use IBus.Publish for publishing message it supports strong type and also it detects the Exchange and Queue name automatically.

Let's assume you have a Message class for adding organizations like this:

[Queue("Organisations.Add", ExchangeName = "Organisations.Add")]
public class Message
{
    public string Text { get; set; }
    public DateTime Date { get; set; }
}

And for publish a message to broker:

using (var bus = RabbitHutch.CreateBus("host=localhost"))
{
    var message = new Message() { Text = "Hello World", Date = DateTime.Now };
    bus.Publish<Message>(message);
}

So you can create multiple messages based on api and use them in Mediator.

sa-es-ir
  • 3,722
  • 2
  • 13
  • 31