| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Net; |
| | | 6 | | using CoreWCF.Channels.Configuration; |
| | | 7 | | using CoreWCF.Configuration; |
| | | 8 | | using CoreWCF.Queue.Common; |
| | | 9 | | using CoreWCF.Queue.Common.Configuration; |
| | | 10 | | using RabbitMQ.Client; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Channels |
| | | 13 | | { |
| | | 14 | | public sealed class RabbitMqTransportBindingElement : QueueBaseTransportBindingElement |
| | | 15 | | { |
| | | 16 | | private const int MaxRabbitMqMessageSize = 536870912; // 512 * (2^20) = 512 MB, max message size as of RabbitMQ |
| | | 17 | | private const int DefaultMaxMessageSize = 65535; // 64K |
| | 12 | 18 | | private long _maxReceivedMessageSize = DefaultMaxMessageSize; |
| | | 19 | | |
| | 3 | 20 | | public RabbitMqTransportBindingElement() |
| | | 21 | | { |
| | 3 | 22 | | } |
| | | 23 | | |
| | | 24 | | private RabbitMqTransportBindingElement(RabbitMqTransportBindingElement other) |
| | 9 | 25 | | : base(other) |
| | | 26 | | { |
| | 9 | 27 | | MaxReceivedMessageSize = other.MaxReceivedMessageSize; |
| | 9 | 28 | | BrokerProtocol = other.BrokerProtocol; |
| | 9 | 29 | | SslOption = other.SslOption; |
| | 9 | 30 | | VirtualHost = other.VirtualHost; |
| | 9 | 31 | | Credentials = other.Credentials; |
| | 9 | 32 | | QueueConfiguration = other.QueueConfiguration; |
| | 9 | 33 | | } |
| | | 34 | | |
| | | 35 | | public override BindingElement Clone() |
| | | 36 | | { |
| | 9 | 37 | | return new RabbitMqTransportBindingElement(this); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public override T GetProperty<T>(BindingContext context) |
| | | 41 | | { |
| | 9 | 42 | | if (context == null) |
| | | 43 | | { |
| | 0 | 44 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 45 | | } |
| | | 46 | | |
| | 9 | 47 | | if (typeof(T) == typeof(ISecurityCapabilities)) |
| | | 48 | | { |
| | 3 | 49 | | return null; |
| | | 50 | | } |
| | | 51 | | |
| | 6 | 52 | | return base.GetProperty<T>(context); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public override QueueTransportPump BuildQueueTransportPump(BindingContext context) |
| | | 56 | | { |
| | 3 | 57 | | var serviceProvider = context.BindingParameters.Find<IServiceProvider>(); |
| | 3 | 58 | | var serviceDispatcher = context.BindingParameters.Find<IServiceDispatcher>(); |
| | 3 | 59 | | return new RabbitMqTransportPump(serviceProvider, serviceDispatcher, SslOption, QueueConfiguration, Credenti |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Gets the scheme used by the binding, soap.amqp |
| | | 64 | | /// </summary> |
| | | 65 | | public override string Scheme |
| | | 66 | | { |
| | 9 | 67 | | get { return CurrentVersion.Scheme; } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// The largest receivable encoded message |
| | | 72 | | /// </summary> |
| | | 73 | | public override long MaxReceivedMessageSize |
| | | 74 | | { |
| | | 75 | | get |
| | | 76 | | { |
| | 12 | 77 | | return _maxReceivedMessageSize; |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | set |
| | | 81 | | { |
| | 9 | 82 | | if (value <= 0 || value > MaxRabbitMqMessageSize) |
| | | 83 | | { |
| | 0 | 84 | | throw new ArgumentOutOfRangeException(nameof(value), value, SR.Format(SR.InvalidMaxReceivedMessageSi |
| | | 85 | | } |
| | | 86 | | |
| | 9 | 87 | | _maxReceivedMessageSize = value; |
| | 9 | 88 | | } |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Specifies the version of the AMQP protocol that should be used to |
| | | 93 | | /// communicate with the broker |
| | | 94 | | /// </summary> |
| | 30 | 95 | | public IProtocol BrokerProtocol { get; set; } = Protocols.DefaultProtocol; |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// SSL configuration for the RabbitMQ queue |
| | | 99 | | /// </summary> |
| | 24 | 100 | | public SslOption SslOption { get; set; } |
| | | 101 | | |
| | | 102 | | /// <summary> |
| | | 103 | | /// Virtual host for the RabbitMQ queue |
| | | 104 | | /// </summary> |
| | 24 | 105 | | public string VirtualHost { get; set; } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Credentials used for accessing the RabbitMQ host |
| | | 109 | | /// </summary> |
| | 24 | 110 | | public ICredentials Credentials { get; set; } |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Configuration used for declaring a queue |
| | | 114 | | /// </summary> |
| | 27 | 115 | | public QueueDeclareConfiguration QueueConfiguration { get; set; } |
| | | 116 | | } |
| | | 117 | | } |