Windows에서 RabbitMQ 사용하는 기본적인 방법입니다.
RabbitMQ는 Erlang 기반으로 동작하여 설치가 필요합니다.
아래 사이트로 이동하여 설치합니다.
https://www.erlang.org/downloads
Index - Erlang/OTP
The official home of the Erlang Programming Language
www.erlang.org
설치..
RabbitMQ 설치 시 만약 Erlang 이 설치되어있지 않으면 아래 창이 뜹니다.
아래 사이트에서 RabbitMQ-Server를 설치하고 실행합니다.
https://www.rabbitmq.com/install-windows.html
Installing on Windows — RabbitMQ
Installing on Windows This guide covers RabbitMQ installation on Windows. It focuses on the two recommended installation options: The guide also covers a few post-installation topics in the context of Windows: and more. These topics are covered in more det
www.rabbitmq.com
설치..
설치가 끝나면 자동시작됩니다
공통적으로 아래 'RabbitMQ.Client' Nuget을 설치합니다.
Server 구성
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace RabbitMQTest.Server
{
internal class Program
{
static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, e) =>
{
var body = e.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" >> Received {0}", message);
};
channel.BasicConsume(queue: "hello",
autoAck: true,
consumer: consumer);
Console.WriteLine(" Wait Received....");
Console.ReadLine();
}
}
}
}
}
Client 구성
using System.Text;
using RabbitMQ.Client;
namespace RabbitMQTest.Client
{
internal class Program
{
static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: "hello",
basicProperties: null,
body: body);
Console.WriteLine(" Send >> {0}", message);
}
}
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
}
왼쪽이 Client, 오른쪽이 Server
[Source]
https://github.com/kei-soft/RabbitMQTest
GitHub - kei-soft/RabbitMQTest
Contribute to kei-soft/RabbitMQTest development by creating an account on GitHub.
github.com
참고
https://www.rabbitmq.com/getstarted.html
RabbitMQ Tutorials — RabbitMQ
RabbitMQ Tutorials These tutorials cover the basics of creating messaging applications using RabbitMQ. You need to have the RabbitMQ server installed to go through the tutorials, please see the installation guide or use the Docker image. Executable version
www.rabbitmq.com
C# 키보드 후킹하기 (0) | 2024.10.21 |
---|---|
C# RabbitMQ Management 실행하기 (0) | 2024.10.14 |
C# Serilog 적용 및 Seq 연동하기 (0) | 2024.10.12 |
dotnet-dump 사용 및 분석하기 (0) | 2024.10.11 |
Aspire 기본 (0) | 2024.10.09 |