Dreamine.Communication.RabbitMQ 1.0.1
Dreamine.Communication.RabbitMQ 통신 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus 클래스 참조sealed

더 자세히 ...

Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus에 대한 상속 다이어그램 :
Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus에 대한 협력 다이어그램:

Public 멤버 함수

 RabbitMqMessageBus (RabbitMqMessageBusOptions options)
 RabbitMqMessageBus (RabbitMqMessageBusOptions options, IRabbitMqConnectionFactory connectionFactory)
Task ConnectAsync (CancellationToken cancellationToken=default)
Task PublishAsync (MessageEnvelope message, CancellationToken cancellationToken=default)
Task SubscribeAsync (string route, Func< MessageEnvelope, CancellationToken, Task > handler, CancellationToken cancellationToken=default)
Task DisconnectAsync (CancellationToken cancellationToken=default)
async ValueTask DisposeAsync ()

속성

ConnectionState State = ConnectionState.Disconnected [get, private set]
TransportKind Kind [get]

Private 멤버 함수

async Task HandleReceivedAsync (RabbitMqDelivery delivery, CancellationToken cancellationToken)
void DeclareTopology (IRabbitMqChannel channel)
void Cleanup ()

정적 Private 멤버 함수

static void ValidateOptions (RabbitMqMessageBusOptions options)

Private 속성

readonly RabbitMqMessageBusOptions _options
readonly IRabbitMqConnectionFactory _connectionFactory
readonly Dictionary< string, List< Func< MessageEnvelope, CancellationToken, Task > > > _handlers = new()
readonly object _syncRoot = new()
IRabbitMqConnection_connection
IRabbitMqChannel_channel
string? _consumerTag

상세한 설명

RabbitMQ Exchange, Queue 및 라우팅 키를 사용하는 메시지 버스입니다.

메시지 봉투는 JSON으로 직렬화되어 RabbitMQ 본문에 저장됩니다.

RabbitMqMessageBus.cs 파일의 26 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ RabbitMqMessageBus() [1/2]

Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.RabbitMqMessageBus ( RabbitMqMessageBusOptions options)
inline

기본 연결 팩토리와 지정한 설정으로 메시지 버스를 초기화합니다.

매개변수
optionsRabbitMQ 연결 및 토폴로지 설정입니다.

RabbitMqMessageBus.cs 파일의 109 번째 라인에서 정의되었습니다.

110 : this(options, new RabbitMqClientConnectionFactory())
111 {
112 }

◆ RabbitMqMessageBus() [2/2]

Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.RabbitMqMessageBus ( RabbitMqMessageBusOptions options,
IRabbitMqConnectionFactory connectionFactory )
inline

설정과 사용자 지정 연결 팩토리로 메시지 버스를 초기화합니다.

매개변수
optionsRabbitMQ 연결 및 토폴로지 설정입니다.
connectionFactory브로커 연결을 생성할 팩토리입니다.
예외
ArgumentNullException필수 입력 인자 중 하나가 null인 경우 발생합니다.

RabbitMqMessageBus.cs 파일의 146 번째 라인에서 정의되었습니다.

149 {
150 _options = options ?? throw new ArgumentNullException(nameof(options));
151 _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
152 ValidateOptions(_options);
153 }

다음을 참조함 : _connectionFactory, _options, ValidateOptions().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 함수 문서화

◆ Cleanup()

void Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.Cleanup ( )
inlineprivate

처리기와 소비자를 정리하고 채널 및 연결을 안전하게 닫아 해제합니다.

RabbitMqMessageBus.cs 파일의 611 번째 라인에서 정의되었습니다.

612 {
613 lock (_syncRoot)
614 {
615 _handlers.Clear();
616 }
617
618 if (_channel is not null)
619 {
620 try
621 {
622 if (!string.IsNullOrWhiteSpace(_consumerTag))
623 {
624 _channel.BasicCancel(_consumerTag);
625 }
626 }
627 catch
628 {
629 // Ignore consumer cancel failure during cleanup.
630 }
631
632 try
633 {
634 if (_channel.IsOpen)
635 {
636 _channel.Close();
637 }
638 }
639 catch
640 {
641 // Ignore channel close failure during cleanup.
642 }
643
644 _channel.Dispose();
645 _channel = null;
646 }
647
648 if (_connection is not null)
649 {
650 try
651 {
652 if (_connection.IsOpen)
653 {
654 _connection.Close();
655 }
656 }
657 catch
658 {
659 // Ignore connection close failure during cleanup.
660 }
661
662 _connection.Dispose();
663 _connection = null;
664 }
665
666 _consumerTag = null;
667 }

다음을 참조함 : _channel, _connection, _consumerTag, _handlers, _syncRoot.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ConnectAsync()

Task Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.ConnectAsync ( CancellationToken cancellationToken = default)
inline

브로커 연결과 채널을 생성하고 구성된 토폴로지를 선언합니다.

매개변수
cancellationToken연결 취소 요청을 감시하는 토큰입니다.
반환값
비동기 연결 작업입니다.

RabbitMqMessageBus.cs 파일의 199 번째 라인에서 정의되었습니다.

200 {
201 cancellationToken.ThrowIfCancellationRequested();
202
203 if (State == ConnectionState.Connected)
204 {
205 return Task.CompletedTask;
206 }
207
208 State = ConnectionState.Connecting;
209
210 try
211 {
212 _connection = _connectionFactory.CreateConnection(_options);
213 _channel = _connection.CreateChannel();
214
215 DeclareTopology(_channel);
216
217 State = ConnectionState.Connected;
218 return Task.CompletedTask;
219 }
220 catch
221 {
222 State = ConnectionState.Faulted;
223 Cleanup();
224 throw;
225 }
226 }

다음을 참조함 : _channel, _connection, _connectionFactory, _options, Cleanup(), DeclareTopology(), State.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ DeclareTopology()

void Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.DeclareTopology ( IRabbitMqChannel channel)
inlineprivate

구성된 Exchange와 Queue를 선언하고 기본 라우팅 키로 바인딩합니다.

매개변수
channel토폴로지를 선언할 열린 채널입니다.

RabbitMqMessageBus.cs 파일의 583 번째 라인에서 정의되었습니다.

584 {
585 channel.ExchangeDeclare(
586 exchange: _options.ExchangeName,
587 type: _options.ExchangeType,
588 durable: _options.Durable,
589 autoDelete: _options.AutoDelete);
590
591 channel.QueueDeclare(
592 queue: _options.QueueName,
593 durable: _options.Durable,
594 exclusive: _options.Exclusive,
595 autoDelete: _options.AutoDelete);
596
597 channel.QueueBind(
598 queue: _options.QueueName,
599 exchange: _options.ExchangeName,
600 routingKey: _options.RoutingKey);
601 }
void QueueBind(string queue, string exchange, string routingKey)
void QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete)
void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete)

다음을 참조함 : _options, Dreamine.Communication.RabbitMQ.Infrastructure.IRabbitMqChannel.ExchangeDeclare(), Dreamine.Communication.RabbitMQ.Infrastructure.IRabbitMqChannel.QueueBind(), Dreamine.Communication.RabbitMQ.Infrastructure.IRabbitMqChannel.QueueDeclare().

다음에 의해서 참조됨 : ConnectAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ DisconnectAsync()

Task Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.DisconnectAsync ( CancellationToken cancellationToken = default)
inline

소비자, 채널 및 브로커 연결을 정리합니다.

매개변수
cancellationToken연결 해제 취소 요청을 감시하는 토큰입니다.
반환값
비동기 연결 해제 작업입니다.

RabbitMqMessageBus.cs 파일의 418 번째 라인에서 정의되었습니다.

419 {
420 cancellationToken.ThrowIfCancellationRequested();
421
422 State = ConnectionState.Disconnecting;
423
424 try
425 {
426 Cleanup();
427 State = ConnectionState.Disconnected;
428 return Task.CompletedTask;
429 }
430 catch
431 {
432 State = ConnectionState.Faulted;
433 throw;
434 }
435 }

다음을 참조함 : Cleanup(), State.

다음에 의해서 참조됨 : DisposeAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ DisposeAsync()

async ValueTask Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.DisposeAsync ( )
inline

RabbitMQ 메시지 버스 연결과 관련 리소스를 비동기적으로 해제합니다.

반환값
비동기 리소스 해제 작업입니다.

RabbitMqMessageBus.cs 파일의 453 번째 라인에서 정의되었습니다.

454 {
455 await DisconnectAsync().ConfigureAwait(false);
456 }

다음을 참조함 : DisconnectAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ HandleReceivedAsync()

async Task Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.HandleReceivedAsync ( RabbitMqDelivery delivery,
CancellationToken cancellationToken )
inlineprivate

브로커 배달 본문을 메시지로 역직렬화하고 라우트 처리기를 실행한 뒤 성공 또는 실패 확인을 전송합니다.

매개변수
delivery처리할 RabbitMQ 배달 정보입니다.
cancellationToken처리기 실행 취소 토큰입니다.
반환값
비동기 배달 처리 작업입니다.
예외
JsonException배달 본문이 올바른 메시지 JSON이 아닌 경우 발생할 수 있습니다.

RabbitMqMessageBus.cs 파일의 498 번째 라인에서 정의되었습니다.

501 {
502 if (_channel is null)
503 {
504 return;
505 }
506
507 try
508 {
509 var message = JsonSerializer.Deserialize<MessageEnvelope>(delivery.Body.Span);
510
511 if (message is null)
512 {
513 _channel.BasicReject(delivery.DeliveryTag, requeue: false);
514 return;
515 }
516
517 var route = string.IsNullOrWhiteSpace(message.Route)
518 ? delivery.RoutingKey
519 : message.Route;
520
521 List<Func<MessageEnvelope, CancellationToken, Task>> handlers;
522
523 lock (_syncRoot)
524 {
525 if (!_handlers.TryGetValue(route, out var routeHandlers) &&
526 !_handlers.TryGetValue(delivery.RoutingKey, out routeHandlers))
527 {
528 handlers = [];
529 }
530 else
531 {
532 handlers = new List<Func<MessageEnvelope, CancellationToken, Task>>(routeHandlers);
533 }
534 }
535
536 if (handlers.Count == 0)
537 {
538 _channel.BasicAck(delivery.DeliveryTag, multiple: false);
539 return;
540 }
541
542 foreach (var handler in handlers)
543 {
544 await handler(message, cancellationToken).ConfigureAwait(false);
545 }
546
547 _channel.BasicAck(delivery.DeliveryTag, multiple: false);
548 }
549 catch
550 {
551 try
552 {
553 _channel.BasicNack(
554 delivery.DeliveryTag,
555 multiple: false,
556 requeue: _options.RequeueOnHandlerError);
557 }
558 catch
559 {
560 // Ignore acknowledgement failure during shutdown or channel fault.
561 }
562
563 throw;
564 }
565 }

다음을 참조함 : _channel, _handlers, _options, _syncRoot, Dreamine.Communication.RabbitMQ.Infrastructure.RabbitMqDelivery.Body, Dreamine.Communication.RabbitMQ.Infrastructure.RabbitMqDelivery.DeliveryTag, Dreamine.Communication.RabbitMQ.Infrastructure.RabbitMqDelivery.RoutingKey.

다음에 의해서 참조됨 : SubscribeAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ PublishAsync()

Task Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.PublishAsync ( MessageEnvelope message,
CancellationToken cancellationToken = default )
inline

메시지를 JSON으로 직렬화하여 구성된 Exchange와 라우팅 키로 발행합니다.

매개변수
message발행할 메시지입니다.
cancellationToken발행 취소 요청을 감시하는 토큰입니다.
반환값
비동기 발행 작업입니다.
예외
InvalidOperationException현재 객체 상태에서 Publish Async 작업을 수행할 수 없는 경우 발생합니다.

RabbitMqMessageBus.cs 파일의 268 번째 라인에서 정의되었습니다.

271 {
272 ArgumentNullException.ThrowIfNull(message);
273 cancellationToken.ThrowIfCancellationRequested();
274
275 if (_channel is null || State != ConnectionState.Connected)
276 {
277 throw new InvalidOperationException("RabbitMQ message bus is not connected.");
278 }
279
280 var route = string.IsNullOrWhiteSpace(message.Route)
281 ? _options.RoutingKey
282 : message.Route;
283
284 var body = JsonSerializer.SerializeToUtf8Bytes(message);
285
286 var properties = _channel.CreateBasicProperties();
287 properties.Persistent = _options.PersistentMessages;
288 properties.ContentType = "application/json";
289 properties.Type = nameof(MessageEnvelope);
290
291 _channel.BasicPublish(
292 exchange: _options.ExchangeName,
293 routingKey: route,
294 mandatory: false,
295 properties: properties,
296 body: body);
297
298 return Task.CompletedTask;
299 }

다음을 참조함 : _channel, _options, State.

◆ SubscribeAsync()

Task Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.SubscribeAsync ( string route,
Func< MessageEnvelope, CancellationToken, Task > handler,
CancellationToken cancellationToken = default )
inline

라우팅 키를 Queue에 바인딩하고 비동기 처리기를 등록합니다.

매개변수
route구독할 라우팅 키입니다.
handler수신 메시지 처리기입니다.
cancellationToken구독 취소 요청을 감시하는 토큰입니다.
반환값
비동기 구독 작업입니다.
예외
InvalidOperationException현재 객체 상태에서 Subscribe Async 작업을 수행할 수 없는 경우 발생합니다.

RabbitMqMessageBus.cs 파일의 349 번째 라인에서 정의되었습니다.

353 {
354 ArgumentException.ThrowIfNullOrWhiteSpace(route);
355 ArgumentNullException.ThrowIfNull(handler);
356 cancellationToken.ThrowIfCancellationRequested();
357
358 if (_channel is null || State != ConnectionState.Connected)
359 {
360 throw new InvalidOperationException("RabbitMQ message bus is not connected.");
361 }
362
363 lock (_syncRoot)
364 {
365 if (!_handlers.TryGetValue(route, out var handlers))
366 {
367 handlers = [];
368 _handlers[route] = handlers;
369 }
370
371 handlers.Add(handler);
372 }
373
374 _channel.QueueBind(
375 queue: _options.QueueName,
376 exchange: _options.ExchangeName,
377 routingKey: route);
378
379 if (!string.IsNullOrWhiteSpace(_consumerTag))
380 {
381 return Task.CompletedTask;
382 }
383
384 _consumerTag = _channel.BasicConsume(
385 queue: _options.QueueName,
386 autoAck: false,
387 onReceived: (delivery, token) => HandleReceivedAsync(
388 delivery,
389 token.CanBeCanceled ? token : cancellationToken));
390
391 return Task.CompletedTask;
392 }

다음을 참조함 : _channel, _consumerTag, _handlers, _options, _syncRoot, HandleReceivedAsync(), State.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ ValidateOptions()

void Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.ValidateOptions ( RabbitMqMessageBusOptions options)
inlinestaticprivate

필수 RabbitMQ 연결 및 토폴로지 설정과 포트 범위를 검증합니다.

매개변수
options검증할 메시지 버스 설정입니다.
예외
ArgumentException필수 문자열 설정이 비어 있는 경우 발생합니다.
ArgumentOutOfRangeException포트가 1~65535 범위를 벗어난 경우 발생합니다.

RabbitMqMessageBus.cs 파일의 701 번째 라인에서 정의되었습니다.

702 {
703 ArgumentException.ThrowIfNullOrWhiteSpace(options.HostName);
704 ArgumentException.ThrowIfNullOrWhiteSpace(options.VirtualHost);
705 ArgumentException.ThrowIfNullOrWhiteSpace(options.UserName);
706 ArgumentException.ThrowIfNullOrWhiteSpace(options.Password);
707 ArgumentException.ThrowIfNullOrWhiteSpace(options.ExchangeName);
708 ArgumentException.ThrowIfNullOrWhiteSpace(options.QueueName);
709 ArgumentException.ThrowIfNullOrWhiteSpace(options.RoutingKey);
710 ArgumentException.ThrowIfNullOrWhiteSpace(options.ExchangeType);
711
712 if (options.Port <= 0 || options.Port > 65535)
713 {
714 throw new ArgumentOutOfRangeException(nameof(options.Port));
715 }
716 }

다음을 참조함 : Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.ExchangeName, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.ExchangeType, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.HostName, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.Password, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.Port, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.QueueName, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.RoutingKey, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.UserName, Dreamine.Communication.RabbitMQ.Options.RabbitMqMessageBusOptions.VirtualHost.

다음에 의해서 참조됨 : RabbitMqMessageBus().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _channel

IRabbitMqChannel? Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._channel
private

channel 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 82 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Cleanup(), ConnectAsync(), HandleReceivedAsync(), PublishAsync(), SubscribeAsync().

◆ _connection

IRabbitMqConnection? Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._connection
private

connection 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 73 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Cleanup(), ConnectAsync().

◆ _connectionFactory

readonly IRabbitMqConnectionFactory Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._connectionFactory
private

connection Factory 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 45 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), RabbitMqMessageBus().

◆ _consumerTag

string? Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._consumerTag
private

consumer Tag 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 91 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Cleanup(), SubscribeAsync().

◆ _handlers

readonly Dictionary<string, List<Func<MessageEnvelope, CancellationToken, Task> > > Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._handlers = new()
private

handlers 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 54 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Cleanup(), HandleReceivedAsync(), SubscribeAsync().

◆ _options

readonly RabbitMqMessageBusOptions Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._options
private

options 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 36 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), DeclareTopology(), HandleReceivedAsync(), PublishAsync(), RabbitMqMessageBus(), SubscribeAsync().

◆ _syncRoot

readonly object Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus._syncRoot = new()
private

sync Root 값을 보관합니다.

RabbitMqMessageBus.cs 파일의 63 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Cleanup(), HandleReceivedAsync(), SubscribeAsync().

속성 문서화

◆ Kind

TransportKind Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.Kind
get

RabbitMQ 전송 방식을 가져옵니다.

RabbitMqMessageBus.cs 파일의 173 번째 라인에서 정의되었습니다.

◆ State

ConnectionState Dreamine.Communication.RabbitMQ.Buses.RabbitMqMessageBus.State = ConnectionState.Disconnected
getprivate set

메시지 버스의 현재 연결 상태를 가져옵니다.

RabbitMqMessageBus.cs 파일의 163 번째 라인에서 정의되었습니다.

163{ get; private set; } = ConnectionState.Disconnected;

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync(), PublishAsync(), SubscribeAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: