.NET에서 Docker를 사용하는 RabbitMQ 대기열
이것은 RabbitMQ
Queue에 대한 4개의 시리즈 중 세 번째 기사입니다. 첫 번째 부분에는 Queue 개념에 대한 간략한 소개가 포함되어 있으며 두 번째 부분에서는 코드의 각 줄에 대해 설명합니다. RabbitMQ 핵심 개념이 제시된 첫 번째 기사와 Docker 및 Producer를 사용한 환경 설정이 단계별로 설명되어 있는 기사를 확인할 수 있습니다.소개
The RabbitMQ Queue is positioned in the Message Broker section with the Exchange , and can be seen as buffer storage, that receives messages through a stream based on the binding key from the Exchange which also receives the messages from one or many Producers . They are acting like a Queue Data Structure, that can be enqueued and dequeued , using the FIFO rule.\
Some tips about the Queues , that I find useful are:
- A
Queuename can't start theamqname, because is restricted by theBrokerfor internal usages. - If the
Queuename is not specified a random one will be assigned to it. -
Queueswith the same name can be created on the same channel, by only the last one will be kept.
Queue properties can be on their site: https://www.rabbitmq.com/queues.html .대기열 만들기
To start creating a Queue firstly the connection to the RabbitMQ server should be built using the ConnectionFactory ; is the same setup as in the previous article about RabbitMQ Exchange using a URI . But in the first article where the Producer is created, the connection was created using explicit properties of ConnectionFactory (i.e. Hostname , UserName and Password ).
연결 설정
As you can see in the below chunk code, all these properties are embedded into one Uri instance.
var factory = new ConnectionFactory
{
Uri = new Uri("amqp://guest:guest@localhost"),
ContinuationTimeout = TimeSpan.MaxValue
};
ConnectionTimeout property was set to its maximum value because I didn't want the connection to expire, but this is just for this article purposes. If you are interested to find all the ConnectionFactory properties, they are well documented here with one example: https://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.2.4/rabbitmq-dotnet-client-3.2.4-client-htmldoc/html/type-RabbitMQ.Client.ConnectionFactory.html . 이 문서를 읽을 때 버전 3.2.4에 대한 설명서입니다. .NET용 RabbitMQ 클라이언트가 업데이트될 수 있으므로 일부 속성이 변경, 사용 중단 또는 제거될 수 있습니다.개발자 입력
You may wonder why the user or the developer input is involved in this, is because this series of articles aboutRabbitMQ is more educational rather than a solution-oriented approach. So I wanted to replicate one to one the http://tryrabbitmq.com/ .NET을 이용한 RabbitMQ의 기본 원리 학습 개념.\따라서 RabbitMQ 서버에 대한 연결이 구축된 후 사용자는 만들고자 하는 번호
Queues를 입력하고 각각의 이름Queue과 이름routing key을 입력해야 합니다.for (var queueIndex = 0; queueIndex < queuesCount; queueIndex++)
{
Console.Write($"Queue[{queueIndex}] name: ");
var queueName = Console.ReadLine();
Console.Write($"Routing key for Queue[{queueIndex}]: ");
var routingKey = Console.ReadLine();
...
연결 설정
When the required properties are entered, for each Queue a Connection and a communication Channel will be created. After that, the Queue is declared, and the bound to the Exchange that has the same name for the entire solution (i.e. test-exchange). If the creation and the binding were ended successfully, then a message is prompted informing the user that the Queue was created.
...
using (IConnection connection = factory.CreateConnection())
{
using (channel = connection.CreateModel())
{
channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
channel.QueueBind(queue: queueName,
exchange: "test-exchange",
routingKey: routingKey);
}
}
Console.WriteLine(value: $"Queue {queueName} created.");
}
QueueDeclare 매개변수
Let's dig a little bit deep into the parameters of the QueueDeclare :
-
queueit's self-evident that it refers to theQueuename; -
durablerepresents the lifetime of theQueuein theBroker, if it's set to false theQueuewill end when theBrokerdoes too; -
autoDeleteis used to specify the lifetime of theQueuebased on its subscriptions. TheQueuewill be deleted if the lastConsumersubscribed to it, unsubscribes; -
argumentsare used to sent information about theQueue(e.g. length limit) to theBroker;
QueueBind 's parameters are self-explanatory, the first one refers to the queueName , the second to the exchangeName and the last one to the routingKey .
결과
After the Queues are created, a message is prompted to the user with how many Queues were created.

생성된
Queues 는 RabbitMQ 관리 페이지에서도 볼 수 있습니다.
이제
Consumer를 생성하기만 하면 전체 토폴로지를 사용할 수 있습니다. Consumer는 다음 기사에서 작성되며 이 시리즈의 마지막 기사입니다.이 기사를 읽어 주셔서 감사합니다. 흥미로웠다면 동료 및 친구들과 공유하십시오. 또는 개선할 수 있는 부분이 있으면 알려주세요.
Reference
이 문제에 관하여(.NET에서 Docker를 사용하는 RabbitMQ 대기열), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/eduardstefanescu/rabbitmq-queue-with-docker-in-net-307d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)