728x90
728x170

Windows에서 RabbitMQ 사용하는 기본적인 방법입니다.
 

1. Erlang  설치

RabbitMQ는 Erlang  기반으로 동작하여 설치가 필요합니다.
아래 사이트로 이동하여 설치합니다.
https://www.erlang.org/downloads

 

Index - Erlang/OTP

The official home of the Erlang Programming Language

www.erlang.org

설치..

 

2. RabbitMQ 설치 및 실행

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

설치..

 설치가 끝나면 자동시작됩니다

3. 프로젝트 구성

공통적으로 아래 '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

 

728x90
그리드형

'C# > RabbitMQ' 카테고리의 다른 글

[C#/RabbitMQ] 추천강의  (0) 2023.09.13
[C#/RabbitMQ] RabbitMQ - Management 실행하기  (0) 2023.08.09
[C#/Rabbit] MQRabbitMQ - 링크  (0) 2018.02.28
Posted by kjun
,