I'm working on app using Microservices. I have to use Microservices and RabbitMq. I have to make 2 microservices Auth and Products. I want to make Auth Microservices using built in Identity. I also have to use RabbitMq. I set up Auth Microservices with working endpoints and Products Microservices with working endpoints. And now i dont know whats next.
After someone login do i have to send a message to a Queue and then read this message on the server? Do i have to send a JWT token to a Queue and then somehow validate it in Products?
How steps should i follow and what logic to make it work? Best explanation is step by step and as simple as possible; So far i have written a function that can add something to the queue.
public async Task SendMessageAsync(string message)
{
var factory = new ConnectionFactory { HostName = "localhost" };
await using IConnection connection = await factory.CreateConnectionAsync();
await using IChannel channel = await connection.CreateChannelAsync();
await channel.QueueDeclareAsync(queue: "RabbitMqTest", durable: false, exclusive: false, autoDelete: false, arguments: null);
byte[] body = Encoding.UTF8.GetBytes(message);
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "RabbitMqTest", body: body);
}
I'm working on app using Microservices. I have to use Microservices and RabbitMq. I have to make 2 microservices Auth and Products. I want to make Auth Microservices using built in Identity. I also have to use RabbitMq. I set up Auth Microservices with working endpoints and Products Microservices with working endpoints. And now i dont know whats next.
After someone login do i have to send a message to a Queue and then read this message on the server? Do i have to send a JWT token to a Queue and then somehow validate it in Products?
How steps should i follow and what logic to make it work? Best explanation is step by step and as simple as possible; So far i have written a function that can add something to the queue.
public async Task SendMessageAsync(string message)
{
var factory = new ConnectionFactory { HostName = "localhost" };
await using IConnection connection = await factory.CreateConnectionAsync();
await using IChannel channel = await connection.CreateChannelAsync();
await channel.QueueDeclareAsync(queue: "RabbitMqTest", durable: false, exclusive: false, autoDelete: false, arguments: null);
byte[] body = Encoding.UTF8.GetBytes(message);
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "RabbitMqTest", body: body);
}
As far as I know, if you want to communicate (like inter-process communication) between the microservices you need the message broker like RabbitMQ. For example, if you have 2 micro services named stock and sales, whenever a sale is over (in sales service) the stock needs to be updated. In this case the RabbitMQ needed. So the sales service put the message in the RabbitMQ queue which is consumed by Stock service to adjust in it. So AFAIK, in your case RabbitMQ is not needed. Also, the authentication related stuff can be handled in "APIGateway" which is a central point located between the client and the microservices. For APIGateway, you can consider to use Ocelot, Yarp etc. Let me know if you have any further questions. Hope this helps!