| | | 1 | | using System; |
| | | 2 | | using RabbitMQ.Client; |
| | | 3 | | using BinaryMessageEncodingBindingElement = System.ServiceModel.Channels.BinaryMessageEncodingBindingElement; |
| | | 4 | | using Binding = System.ServiceModel.Channels.Binding; |
| | | 5 | | using BindingElementCollection = System.ServiceModel.Channels.BindingElementCollection; |
| | | 6 | | using TextMessageEncodingBindingElement = System.ServiceModel.Channels.TextMessageEncodingBindingElement; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.ServiceModel.Channels |
| | | 9 | | { |
| | | 10 | | public class RabbitMqBinding : Binding |
| | | 11 | | { |
| | | 12 | | private RabbitMqTransportBindingElement _transport; |
| | | 13 | | private TextMessageEncodingBindingElement _textMessageEncodingBindingElement; |
| | | 14 | | private BinaryMessageEncodingBindingElement _binaryMessageEncodingBindingElement; |
| | 3 | 15 | | private RabbitMqMessageEncoding _messageEncoding = RabbitMqMessageEncoding.Text; |
| | | 16 | | |
| | 3 | 17 | | public RabbitMqBinding() |
| | | 18 | | { |
| | 3 | 19 | | _textMessageEncodingBindingElement = new TextMessageEncodingBindingElement(); |
| | 3 | 20 | | _binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); |
| | | 21 | | |
| | 3 | 22 | | var sslOption = new SslOption(); |
| | 3 | 23 | | var virtualHost = ConnectionFactory.DefaultVHost; |
| | | 24 | | |
| | 3 | 25 | | _transport = new RabbitMqTransportBindingElement |
| | 3 | 26 | | { |
| | 3 | 27 | | SslOption = sslOption, |
| | 3 | 28 | | VirtualHost = virtualHost |
| | 3 | 29 | | }; |
| | 3 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Specifies the maximum encoded message size |
| | | 34 | | /// </summary> |
| | | 35 | | public long MaxMessageSize |
| | | 36 | | { |
| | 0 | 37 | | get => _transport.MaxReceivedMessageSize; |
| | 0 | 38 | | set => _transport.MaxReceivedMessageSize = value; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Specifies the version of the AMQP protocol that should be used to communicate with the broker |
| | | 43 | | /// </summary> |
| | | 44 | | public IProtocol BrokerProtocol |
| | | 45 | | { |
| | 0 | 46 | | get => _transport.BrokerProtocol; |
| | 0 | 47 | | set => _transport.BrokerProtocol = value; |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public SslOption SslOption |
| | | 51 | | { |
| | 0 | 52 | | get => _transport.SslOption; |
| | 0 | 53 | | set => _transport.SslOption = value; |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets the scheme used by the binding |
| | | 58 | | /// </summary> |
| | 0 | 59 | | public override string Scheme => _transport.Scheme; |
| | | 60 | | |
| | | 61 | | public RabbitMqMessageEncoding MessageEncoding |
| | | 62 | | { |
| | | 63 | | get |
| | | 64 | | { |
| | 27 | 65 | | return _messageEncoding; |
| | | 66 | | } |
| | | 67 | | set |
| | | 68 | | { |
| | 0 | 69 | | if (!Enum.IsDefined(typeof(RabbitMqMessageEncoding), value)) |
| | | 70 | | { |
| | 0 | 71 | | throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidEnumValue, value)); |
| | | 72 | | } |
| | 0 | 73 | | _messageEncoding = value; |
| | 0 | 74 | | } |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | public override BindingElementCollection CreateBindingElements() |
| | | 78 | | { |
| | 27 | 79 | | BindingElementCollection elements = new BindingElementCollection(); |
| | | 80 | | |
| | 27 | 81 | | switch (MessageEncoding) |
| | | 82 | | { |
| | | 83 | | case RabbitMqMessageEncoding.Binary: |
| | 0 | 84 | | elements.Add(_binaryMessageEncodingBindingElement); |
| | 0 | 85 | | break; |
| | | 86 | | case RabbitMqMessageEncoding.Text: |
| | 27 | 87 | | elements.Add(_textMessageEncodingBindingElement); |
| | 27 | 88 | | break; |
| | | 89 | | default: |
| | 0 | 90 | | elements.Add(_textMessageEncodingBindingElement); |
| | | 91 | | break; |
| | | 92 | | } |
| | | 93 | | |
| | 27 | 94 | | elements.Add(_transport); |
| | | 95 | | |
| | 27 | 96 | | return elements; |
| | | 97 | | } |
| | | 98 | | } |
| | | 99 | | } |