Dreamine.Communication.RabbitMQ 1.0.1
Dreamine.Communication.RabbitMQ 통신 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
RabbitMqClientConnectionFactory.cs
이 파일의 문서화 페이지로 가기
2using RabbitMQ.Client;
3using RabbitMQ.Client.Events;
4
6
16{
50 {
51 ArgumentNullException.ThrowIfNull(options);
52
53 var factory = new ConnectionFactory
54 {
55 HostName = options.HostName,
56 Port = options.Port,
57 VirtualHost = options.VirtualHost,
58 UserName = options.UserName,
59 Password = options.Password,
60 DispatchConsumersAsync = true
61 };
62
63 return new RabbitMqClientConnection(factory.CreateConnection());
64 }
65
75 {
84 private readonly IConnection _connection;
85
102 public RabbitMqClientConnection(IConnection connection)
103 {
104 _connection = connection;
105 }
106
115 public bool IsOpen => _connection.IsOpen;
116
134 {
135 return new RabbitMqClientChannel(_connection.CreateModel());
136 }
137
146 public void Close()
147 {
148 _connection.Close();
149 }
150
159 public void Dispose()
160 {
161 _connection.Dispose();
162 }
163 }
164
174 {
183 private readonly IModel _channel;
184
201 public RabbitMqClientChannel(IModel channel)
202 {
203 _channel = channel;
204 }
205
214 public bool IsOpen => _channel.IsOpen;
215
256 public void ExchangeDeclare(
257 string exchange,
258 string type,
259 bool durable,
260 bool autoDelete)
261 {
262 _channel.ExchangeDeclare(exchange, type, durable, autoDelete, arguments: null);
263 }
264
305 public void QueueDeclare(
306 string queue,
307 bool durable,
308 bool exclusive,
309 bool autoDelete)
310 {
311 _channel.QueueDeclare(queue, durable, exclusive, autoDelete, arguments: null);
312 }
313
346 public void QueueBind(
347 string queue,
348 string exchange,
349 string routingKey)
350 {
351 _channel.QueueBind(queue, exchange, routingKey);
352 }
353
371 {
372 return new RabbitMqClientBasicProperties(_channel.CreateBasicProperties());
373 }
374
423 public void BasicPublish(
424 string exchange,
425 string routingKey,
426 bool mandatory,
427 IRabbitMqBasicProperties properties,
428 ReadOnlyMemory<byte> body)
429 {
430 var clientProperties = properties is RabbitMqClientBasicProperties wrapped
431 ? wrapped.Inner
432 : _channel.CreateBasicProperties();
433
434 clientProperties.Persistent = properties.Persistent;
435 clientProperties.ContentType = properties.ContentType;
436 clientProperties.Type = properties.Type;
437
438 _channel.BasicPublish(exchange, routingKey, mandatory, clientProperties, body);
439 }
440
481 public string BasicConsume(
482 string queue,
483 bool autoAck,
484 Func<RabbitMqDelivery, CancellationToken, Task> onReceived)
485 {
486 var consumer = new AsyncEventingBasicConsumer(_channel);
487 consumer.Received += async (_, args) =>
488 {
489 var delivery = new RabbitMqDelivery(args.DeliveryTag, args.RoutingKey, args.Body);
490 await onReceived(delivery, CancellationToken.None).ConfigureAwait(false);
491 };
492
493 return _channel.BasicConsume(queue, autoAck, consumer);
494 }
495
520 public void BasicAck(ulong deliveryTag, bool multiple)
521 {
522 _channel.BasicAck(deliveryTag, multiple);
523 }
524
557 public void BasicNack(ulong deliveryTag, bool multiple, bool requeue)
558 {
559 _channel.BasicNack(deliveryTag, multiple, requeue);
560 }
561
586 public void BasicReject(ulong deliveryTag, bool requeue)
587 {
588 _channel.BasicReject(deliveryTag, requeue);
589 }
590
607 public void BasicCancel(string consumerTag)
608 {
609 _channel.BasicCancel(consumerTag);
610 }
611
620 public void Close()
621 {
622 _channel.Close();
623 }
624
633 public void Dispose()
634 {
635 _channel.Dispose();
636 }
637 }
638
648 {
665 public RabbitMqClientBasicProperties(IBasicProperties inner)
666 {
667 Inner = inner;
668 }
669
678 public IBasicProperties Inner { get; }
679
688 public bool Persistent
689 {
690 get => Inner.Persistent;
691 set => Inner.Persistent = value;
692 }
693
702 public string? ContentType
703 {
704 get => Inner.ContentType;
705 set => Inner.ContentType = value;
706 }
707
716 public string? Type
717 {
718 get => Inner.Type;
719 set => Inner.Type = value;
720 }
721 }
722}
string BasicConsume(string queue, bool autoAck, Func< RabbitMqDelivery, CancellationToken, Task > onReceived)
void BasicPublish(string exchange, string routingKey, bool mandatory, IRabbitMqBasicProperties properties, ReadOnlyMemory< byte > body)