Esempio n. 1
0
 public JsonMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _deserializer            = deserializer;
     _objectTypeDeserializer  = new ObjectTypeDeserializer(_deserializer);
     _sendEndpointProvider    = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
        public void Apply(IBusBuilder builder)
        {
            var rabbitMqBusBuilder = builder as RabbitMqBusBuilder;

            if (rabbitMqBusBuilder == null)
            {
                throw new ConfigurationException("Must be a RabbitMqBusBuilder");
            }

            var receiveEndpointBuilder = new RabbitMqReceiveEndpointBuilder(builder, _host, rabbitMqBusBuilder.Hosts, _bindMessageExchanges, _configuration);

            var receivePipe = CreateReceivePipe(receiveEndpointBuilder);

            var receiveEndpointTopology = receiveEndpointBuilder.CreateReceiveEndpointTopology(InputAddress, _settings);

            _sendEndpointProvider    = receiveEndpointTopology.SendEndpointProvider;
            _publishEndpointProvider = receiveEndpointTopology.PublishEndpointProvider;

            var transport = new RabbitMqReceiveTransport(_host, _settings, _managementPipe, receiveEndpointTopology);

            var rabbitMqHost = _host as RabbitMqHost;

            if (rabbitMqHost == null)
            {
                throw new ConfigurationException("Must be a RabbitMqHost");
            }

            rabbitMqHost.ReceiveEndpoints.Add(_settings.QueueName ?? NewId.Next().ToString(), new ReceiveEndpoint(transport, receivePipe));
        }
Esempio n. 3
0
 public MessageReceiverFilter(IPipe <ReceiveContext> receivePipe, ISendEndpointProvider sendEndpointProvider,
                              IPublishEndpointProvider publishEndpointProvider)
 {
     _receivePipe             = receivePipe;
     _sendEndpointProvider    = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
 public BinaryMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider,
     IPublishEndpointProvider publishEndpoint)
 {
     _deserializer = deserializer;
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpoint = publishEndpoint;
 }
 public MoveExceptionToTransportFilter(IPublishEndpointProvider publishEndpoint, Uri destinationAddress,
                                       Func <Task <ISendTransport> > getDestinationTransport)
 {
     _getDestinationTransport = getDestinationTransport;
     _publishEndpoint         = publishEndpoint;
     _destinationAddress      = destinationAddress;
 }
Esempio n. 6
0
        public void Apply(IInMemoryBusBuilder builder)
        {
            var inMemoryBusBuilder = builder as InMemoryBusBuilder;

            if (inMemoryBusBuilder == null)
            {
                throw new ArgumentException("The bus builder is expected to by an InMemoryBusBuilder", nameof(inMemoryBusBuilder));
            }

            var inMemoryHost = inMemoryBusBuilder.InMemoryHost as InMemoryHost;

            if (inMemoryHost == null)
            {
                throw new ConfigurationException("Must be an InMemoryHost");
            }

            var receiveEndpointBuilder = new InMemoryReceiveEndpointBuilder(builder, inMemoryHost, _sendTransportProvider, _configuration);

            var receivePipe = CreateReceivePipe(receiveEndpointBuilder);

            var receiveEndpointTopology = receiveEndpointBuilder.CreateReceiveEndpointTopology(InputAddress);

            _sendEndpointProvider    = receiveEndpointTopology.SendEndpointProvider;
            _publishEndpointProvider = receiveEndpointTopology.PublishEndpointProvider;

            var transport = inMemoryBusBuilder.InMemoryHost.GetReceiveTransport(_queueName, receiveEndpointTopology);

            inMemoryHost.ReceiveEndpoints.Add(_queueName, new ReceiveEndpoint(transport, receivePipe));
        }
        public ServiceBusReceiveContext(Uri inputAddress, BrokeredMessage message, IReceiveObserver observer, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(inputAddress, message.DeliveryCount > 1, observer, sendEndpointProvider, publishEndpointProvider)
        {
            _message = message;

            GetOrAddPayload<BrokeredMessageContext>(() => this);
        }
 public JsonMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _deserializer = deserializer;
     _objectTypeDeserializer = new ObjectTypeDeserializer(_deserializer);
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
 public BsonMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider,
                                IPublishEndpointProvider publishEndpoint)
 {
     _deserializer         = deserializer;
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpoint      = publishEndpoint;
 }
Esempio n. 10
0
        public void Apply(IInMemoryBusBuilder builder)
        {
            var receiveEndpointBuilder = new InMemoryReceiveEndpointBuilder(CreateConsumePipe(builder), builder);

            var receivePipe = CreateReceivePipe(receiveEndpointBuilder);

            _sendEndpointProvider    = CreateSendEndpointProvider(receiveEndpointBuilder);
            _publishEndpointProvider = CreatePublishEndpointProvider(receiveEndpointBuilder);

            var inMemoryBusBuilder = builder as InMemoryBusBuilder;

            if (inMemoryBusBuilder == null)
            {
                throw new ArgumentException("The bus builder is expected to by an InMemoryBusBuilder", nameof(inMemoryBusBuilder));
            }

            var transport = inMemoryBusBuilder.InMemoryHost.GetReceiveTransport(_queueName, _transportConcurrencyLimit, _sendEndpointProvider,
                                                                                _publishEndpointProvider);

            var inMemoryHost = inMemoryBusBuilder.InMemoryHost as InMemoryHost;

            if (inMemoryHost == null)
            {
                throw new ConfigurationException("Must be an InMemoryHost");
            }

            inMemoryHost.ReceiveEndpoints.Add(_queueName, new ReceiveEndpoint(transport, receivePipe));
        }
        public HttpReceiveContext(IOwinContext requestContext, bool redelivered, IReceiveObserver receiveObserver,
            ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(requestContext.Request.Uri, redelivered, receiveObserver, sendEndpointProvider, publishEndpointProvider)
        {
            _requestContext = requestContext;

            HeaderProvider = new HttpHeaderProvider(requestContext.Request.Headers);
        }
 public EncryptedMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider,
     IPublishEndpointProvider publishEndpoint, ICryptoStreamProvider provider)
 {
     _deserializer = deserializer;
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpoint = publishEndpoint;
     _provider = provider;
 }
Esempio n. 13
0
 public Settings(string pathMatch, IMessageSerializer messageSerializer, ISendEndpointProvider sendEndpointProvider,
                 IPublishEndpointProvider publishEndpointProvider)
 {
     PathMatch               = pathMatch;
     MessageSerializer       = messageSerializer;
     SendEndpointProvider    = sendEndpointProvider;
     PublishEndpointProvider = publishEndpointProvider;
 }
Esempio n. 14
0
 public PublishEndpoint(Uri sourceAddress, IPublishEndpointProvider endpointProvider, IPublishObserver publishObserver, Guid?correlationId, Guid?conversationId)
 {
     _sourceAddress    = sourceAddress;
     _endpointProvider = endpointProvider;
     _publishObserver  = publishObserver;
     _correlationId    = correlationId;
     _conversationId   = conversationId;
 }
        public HttpReceiveContext(IOwinContext requestContext, bool redelivered, IReceiveObserver receiveObserver,
                                  ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(requestContext.Request.Uri, redelivered, receiveObserver, sendEndpointProvider, publishEndpointProvider)
        {
            _requestContext = requestContext;

            HeaderProvider = new HttpHeaderProvider(requestContext.Request.Headers);
        }
 public EncryptedMessageDeserializer(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider,
                                     IPublishEndpointProvider publishEndpoint, ICryptoStreamProvider provider)
 {
     _deserializer         = deserializer;
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpoint      = publishEndpoint;
     _provider             = provider;
 }
        public InMemoryReceiveContext(Uri inputAddress, InMemoryTransportMessage message, IReceiveObserver observer, ISendEndpointProvider sendEndpointProvider,
            IPublishEndpointProvider publishEndpointProvider)
            : base(inputAddress, message.DeliveryCount > 0, observer, sendEndpointProvider, publishEndpointProvider)
        {
            _body = message.Body;
            _message = message;

            GetOrAddPayload(() => this);
        }
Esempio n. 18
0
 public PublishEndpoint(Uri sourceAddress, IPublishEndpointProvider endpointProvider, IPublishObserver publishObserver, IPublishPipe publishPipe,
                        ConsumeContext consumeContext)
 {
     _sourceAddress    = sourceAddress;
     _endpointProvider = endpointProvider;
     _publishObserver  = publishObserver;
     _publishPipe      = publishPipe;
     _consumeContext   = consumeContext;
 }
Esempio n. 19
0
 public RabbitMqConsumerFilter(IPipe <ReceiveContext> receivePipe, IReceiveObserver receiveObserver, IReceiveTransportObserver transportObserver, ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _receivePipe             = receivePipe;
     _receiveObserver         = receiveObserver;
     _transportObserver       = transportObserver;
     _supervisor              = supervisor;
     _sendEndpointProvider    = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
        public HttpClientReceiveContext(HttpResponseMessage responseMessage, Stream responseStream, bool redelivered, IReceiveObserver receiveObserver,
            ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(responseMessage.RequestMessage.RequestUri, redelivered, receiveObserver, sendEndpointProvider, publishEndpointProvider)
        {
            _responseMessage = responseMessage;
            _responseStream = responseStream;

            HeaderProvider = new HttpClientHeaderProvider(responseMessage.Headers);
        }
Esempio n. 21
0
        public HttpClientReceiveContext(HttpResponseMessage responseMessage, Stream responseStream, bool redelivered, IReceiveObserver receiveObserver,
                                        ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(responseMessage.RequestMessage.RequestUri, redelivered, receiveObserver, sendEndpointProvider, publishEndpointProvider)
        {
            _responseMessage = responseMessage;
            _responseStream  = responseStream;

            HeaderProvider = new HttpClientHeaderProvider(responseMessage.Headers);
        }
Esempio n. 22
0
        public InMemoryReceiveContext(Uri inputAddress, InMemoryTransportMessage message, IReceiveObserver observer, ISendEndpointProvider sendEndpointProvider,
                                      IPublishEndpointProvider publishEndpointProvider)
            : base(inputAddress, message.DeliveryCount > 0, observer, sendEndpointProvider, publishEndpointProvider)
        {
            _body    = message.Body;
            _message = message;

            GetOrAddPayload(() => this);
        }
        protected BaseConsumeContext(ReceiveContext receiveContext, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _receiveContext          = receiveContext;
            _sendEndpointProvider    = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;

            _publishEndpoint =
                new Lazy <IPublishEndpoint>(() => _publishEndpointProvider.CreatePublishEndpoint(_receiveContext.InputAddress, CorrelationId, ConversationId));
        }
Esempio n. 24
0
 public StaticConsumeContext(ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider,
     ReceiveContext receiveContext, object message, Header[] headers)
     : base(receiveContext, sendEndpointProvider, publishEndpointProvider)
 {
     _messageTypes = new Dictionary<Type, object>();
     _message = message;
     _binaryHeaders = headers;
     _supportedTypes = GetSupportedMessageTypes().ToArray();
 }
 public ProtocolBuffersConsumeContext(ISendEndpointProvider sendEndpointProvider,
                                      IPublishEndpointProvider publishEndpointProvider, ReceiveContext receiveContext, ProtocolBuffersMessageEnvelope envelope, long offset)
     : base(receiveContext, sendEndpointProvider, publishEndpointProvider)
 {
     _envelope               = envelope;
     _offset                 = offset;
     _supportedTypes         = envelope.MessageType.ToArray();
     _messageTypes           = new Dictionary <Type, object>();
     _objectTypeDeserializer = null;
 }
Esempio n. 26
0
        public HttpReceiveTransport(IHttpHost host, ReceiveSettings receiveSettings, IPublishEndpointProvider publishEndpointProvider, ISendPipe sendPipe)
        {
            _host                    = host;
            _receiveSettings         = receiveSettings;
            _publishEndpointProvider = publishEndpointProvider;
            _sendPipe                = sendPipe;

            _receiveObservable          = new ReceiveObservable();
            _receiveTransportObservable = new ReceiveTransportObservable();
        }
 public MessageSessionAsyncHandlerFactory(NamespaceContext context, ITaskSupervisor supervisor, ISessionReceiver receiver, IDeliveryTracker tracker,
     ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _context = context;
     _supervisor = supervisor;
     _receiver = receiver;
     _tracker = tracker;
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
 public MessageSessionAsyncHandlerFactory(NamespaceContext context, ITaskSupervisor supervisor, ISessionReceiver receiver, IDeliveryTracker tracker,
                                          ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _context                 = context;
     _supervisor              = supervisor;
     _receiver                = receiver;
     _tracker                 = tracker;
     _sendEndpointProvider    = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
Esempio n. 29
0
 public ReceiveTransport(IServiceBusHost host, ClientSettings settings, IPublishEndpointProvider publishEndpointProvider,
                         IPipeSpecification <NamespaceContext>[] specifications)
 {
     _host     = host;
     _settings = settings;
     _publishEndpointProvider = publishEndpointProvider;
     _specifications          = specifications;
     _receiveObservers        = new ReceiveObservable();
     _endpointObservers       = new ReceiveTransportObservable();
 }
        /// <summary>
        /// Adds a RabbitMQ Basic Consumer to the pipeline
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="pipe"></param>
        /// <param name="settings"></param>
        /// <param name="receiveObserver"></param>
        /// <param name="transportObserver"></param>
        /// <param name="exchangeBindings"></param>
        /// <param name="supervisor"></param>
        /// <param name="managementPipe"></param>
        /// <param name="sendEndpointProvider"></param>
        /// <param name="publishEndpointProvider"></param>
        /// <param name="host"></param>
        public static void RabbitMqConsumer(this IPipeConfigurator<ConnectionContext> configurator, IPipe<ReceiveContext> pipe, ReceiveSettings settings, IReceiveObserver receiveObserver, IReceiveTransportObserver transportObserver, IEnumerable<ExchangeBindingSettings> exchangeBindings, ITaskSupervisor supervisor, IManagementPipe managementPipe, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider, IRabbitMqHost host)
        {
            if (configurator == null)
                throw new ArgumentNullException(nameof(configurator));

            var pipeBuilderConfigurator = new RabbitMqConsumerPipeSpecification(pipe, settings, receiveObserver, transportObserver, exchangeBindings,
                supervisor, managementPipe, sendEndpointProvider, publishEndpointProvider, host);

            configurator.AddPipeSpecification(pipeBuilderConfigurator);
        }
Esempio n. 31
0
        void ConfigureRescueFilter(IPublishEndpointProvider publishEndpoint, ISendTransportProvider transportProvider)
        {
            IPipe <ExceptionReceiveContext> moveToErrorPipe = Pipe.New <ExceptionReceiveContext>(x =>
            {
                Func <Task <ISendTransport> > getErrorTransport = () => transportProvider.GetSendTransport(_errorAddress.Value);

                x.UseFilter(new MoveExceptionToTransportFilter(publishEndpoint, _errorAddress.Value, getErrorTransport));
            });

            _receiveConfigurator.UseRescue(moveToErrorPipe);
        }
Esempio n. 32
0
 public JsonConsumeContext(JsonSerializer deserializer, IObjectTypeDeserializer objectTypeDeserializer, ISendEndpointProvider sendEndpointProvider,
                           IPublishEndpointProvider publishEndpointProvider, ReceiveContext receiveContext, MessageEnvelope envelope)
     : base(receiveContext, sendEndpointProvider, publishEndpointProvider)
 {
     _envelope               = envelope;
     _deserializer           = deserializer;
     _objectTypeDeserializer = objectTypeDeserializer;
     _messageToken           = GetMessageToken(envelope.Message);
     _supportedTypes         = envelope.MessageType.ToArray();
     _messageTypes           = new Dictionary <Type, object>();
 }
Esempio n. 33
0
        public ReceiveTransport(IServiceBusHost host, ClientSettings settings, IPublishEndpointProvider publishEndpointProvider,
                                ISendEndpointProvider sendEndpointProvider, IPipe <NamespaceContext> pipe)
        {
            _host     = host;
            _settings = settings;
            _publishEndpointProvider = publishEndpointProvider;
            _sendEndpointProvider    = sendEndpointProvider;
            _pipe = pipe;

            _receiveObservers  = new ReceiveObservable();
            _endpointObservers = new ReceiveTransportObservable();
        }
Esempio n. 34
0
        public async Task UnlinkClient(IPublishEndpointProvider publishEndpointProvider)
        {
            try
            {
                var sendEndpoint = await publishEndpointProvider.GetPublishSendEndpoint <Unlink <TMessage> >().ConfigureAwait(false);

                await sendEndpoint.Send <Unlink <TMessage> >(new { ClientId }).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                LogContext.Warning?.Log(exception, "Failed to unlink client: {MessageType}", TypeMetadataCache <TMessage> .ShortName);
            }
        }
        public RabbitMqReceiveContext(Uri inputAddress, string exchange, string routingKey, string consumerTag, ulong deliveryTag, byte[] body, bool redelivered,
            IBasicProperties properties, IReceiveObserver observer, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
            : base(inputAddress, redelivered, observer, sendEndpointProvider, publishEndpointProvider)
        {
            Exchange = exchange;
            RoutingKey = routingKey;
            ConsumerTag = consumerTag;
            DeliveryTag = deliveryTag;
            _body = body;
            Properties = properties;

            ((ReceiveContext)this).GetOrAddPayload<RabbitMqBasicConsumeContext>(() => this);
        }
Esempio n. 36
0
        public SessionReceiver(ClientContext clientContext, IPipe<ReceiveContext> receivePipe, ClientSettings clientSettings, ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _clientContext = clientContext;
            _receivePipe = receivePipe;
            _clientSettings = clientSettings;
            _supervisor = supervisor;
            _sendEndpointProvider = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;

            _tracker = new DeliveryTracker(HandleDeliveryComplete);

            _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {clientContext.InputAddress}", Stop);
        }
Esempio n. 37
0
        public ReceiveTransport(IServiceBusHost host, ClientSettings settings, IPublishEndpointProvider publishEndpointProvider,
                                ISendEndpointProvider sendEndpointProvider, IClientCache clientCache, IPipe <ClientContext> clientPipe, ReceiveTransportObservable transportObserver)
        {
            _host     = host;
            _settings = settings;
            _publishEndpointProvider = publishEndpointProvider;
            _sendEndpointProvider    = sendEndpointProvider;
            _clientCache             = clientCache;
            _clientPipe = clientPipe;

            _observers          = new ReceiveObservable();
            _transportObservers = transportObserver;
        }
Esempio n. 38
0
        public MassTransitBus(Uri address, IConsumePipe consumePipe, ISendEndpointProvider sendEndpointProvider,
                              IPublishEndpointProvider publishEndpointProvider, IBusHostCollection hosts,
                              IBusObserver busObservable)
        {
            Address                  = address;
            _consumePipe             = consumePipe;
            _sendEndpointProvider    = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;
            _busObservable           = busObservable;
            _hosts = hosts;

            _publishEndpoint = new Lazy <IPublishEndpoint>(() => publishEndpointProvider.CreatePublishEndpoint(address));
        }
Esempio n. 39
0
        public SessionReceiver(ClientContext clientContext, IPipe <ReceiveContext> receivePipe, ClientSettings clientSettings, ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _clientContext           = clientContext;
            _receivePipe             = receivePipe;
            _clientSettings          = clientSettings;
            _supervisor              = supervisor;
            _sendEndpointProvider    = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;

            _tracker = new DeliveryTracker(HandleDeliveryComplete);

            _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {clientContext.InputAddress}", Stop);
        }
        public RabbitMqReceiveTransport(IRabbitMqHost host, ReceiveSettings settings, IManagementPipe managementPipe, ExchangeBindingSettings[] bindings, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _host = host;
            _settings = settings;
            _bindings = bindings;
            _sendEndpointProvider = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;
            _managementPipe = managementPipe;

            _receiveObservable = new ReceiveObservable();
            _receiveTransportObservable = new ReceiveTransportObservable();

            _inputAddress = _settings.GetInputAddress(_host.Settings.HostAddress);
        }
Esempio n. 41
0
        public JsonConsumeContext(JsonSerializer deserializer, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider,
                                  ReceiveContext receiveContext, MessageEnvelope envelope)
        {
            _receiveContext          = receiveContext;
            _envelope                = envelope;
            _sendEndpointProvider    = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;
            _deserializer            = deserializer;
            _messageToken            = GetMessageToken(envelope.Message);
            _supportedTypes          = envelope.MessageType.ToArray();
            _messageTypes            = new Dictionary <Type, object>();

            _publishEndpoint = new Lazy <IPublishEndpoint>(() => _publishEndpointProvider.CreatePublishEndpoint(_receiveContext.InputAddress, CorrelationId, ConversationId));
        }
Esempio n. 42
0
        public RabbitMqReceiveTransport(IRabbitMqHost host, ReceiveSettings settings, IManagementPipe managementPipe, ExchangeBindingSettings[] bindings, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _host                    = host;
            _settings                = settings;
            _bindings                = bindings;
            _sendEndpointProvider    = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;
            _managementPipe          = managementPipe;

            _receiveObservable          = new ReceiveObservable();
            _receiveTransportObservable = new ReceiveTransportObservable();

            _inputAddress = _settings.GetInputAddress(_host.Settings.HostAddress);
        }
        /// <summary>
        /// The basic consumer receives messages pushed from the broker.
        /// </summary>
        /// <param name="model">The model context for the consumer</param>
        /// <param name="inputAddress">The input address for messages received by the consumer</param>
        /// <param name="receivePipe">The receive pipe to dispatch messages</param>
        /// <param name="receiveObserver">The observer for receive events</param>
        /// <param name="taskSupervisor">The token used to cancel/stop the consumer at shutdown</param>
        /// <param name="sendEndpointProvider"></param>
        /// <param name="publishEndpointProvider"></param>
        public RabbitMqBasicConsumer(ModelContext model, Uri inputAddress, IPipe<ReceiveContext> receivePipe, IReceiveObserver receiveObserver, ITaskScope taskSupervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _model = model;
            _inputAddress = inputAddress;
            _receivePipe = receivePipe;
            _receiveObserver = receiveObserver;
            _sendEndpointProvider = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;

            _tracker = new DeliveryTracker(HandleDeliveryComplete);

            _receiveSettings = model.GetPayload<ReceiveSettings>();

            _pending = new ConcurrentDictionary<ulong, RabbitMqReceiveContext>();

            _participant = taskSupervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqBasicConsumer>.ShortName} - {inputAddress}", Stop);
            _deliveryComplete = new TaskCompletionSource<bool>();
        }
Esempio n. 44
0
        public Receiver(NamespaceContext context, ClientContext clientContext, IPipe<ReceiveContext> receivePipe, ClientSettings clientSettings,
            ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            _context = context;
            _clientContext = clientContext;
            _receivePipe = receivePipe;
            _clientSettings = clientSettings;
            _sendEndpointProvider = sendEndpointProvider;
            _publishEndpointProvider = publishEndpointProvider;

            _tracker = new DeliveryTracker(DeliveryComplete);

            _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {clientContext.InputAddress}", Stop);

            var options = new OnMessageOptions
            {
                AutoComplete = false,
                AutoRenewTimeout = clientSettings.AutoRenewTimeout,
                MaxConcurrentCalls = clientSettings.MaxConcurrentCalls
            };

            options.ExceptionReceived += (sender, x) =>
            {
                if (!(x.Exception is OperationCanceledException))
                {
                    if (_log.IsErrorEnabled)
                        _log.Error($"Exception received on receiver: {clientContext.InputAddress} during {x.Action}", x.Exception);
                }

                if (_tracker.ActiveDeliveryCount == 0)
                {
                    if (_log.IsDebugEnabled)
                        _log.DebugFormat("Receiver shutdown completed: {0}", clientContext.InputAddress);

                    _participant.SetComplete();
                }
            };

            clientContext.OnMessageAsync(OnMessage, options);

            _participant.SetReady();
        }
        public void Apply(IBusBuilder builder)
        {
            var receiveEndpointBuilder = new HttpReceiveEndpointBuilder(_host, CreateConsumePipe(builder), builder);

            var receivePipe = CreateReceivePipe(receiveEndpointBuilder);

            _sendEndpointProvider = CreateSendEndpointProvider(receiveEndpointBuilder);
            _publishEndpointProvider = CreatePublishEndpointProvider(receiveEndpointBuilder);

            var sendPipe = builder.CreateSendPipe();

            var receiveSettings = new Settings(_pathMatch, receiveEndpointBuilder.MessageSerializer, _sendEndpointProvider, _publishEndpointProvider);

            var transport = new HttpReceiveTransport(_host, receiveSettings, sendPipe);

            var httpHost = _host as HttpHost;
            if (httpHost == null)
                throw new ConfigurationException("Must be a HttpHost");

            httpHost.ReceiveEndpoints.Add(NewId.Next().ToString(), new ReceiveEndpoint(transport, receivePipe));
        }
        public void Apply(IInMemoryBusBuilder builder)
        {
            var receiveEndpointBuilder = new InMemoryReceiveEndpointBuilder(CreateConsumePipe(builder), builder);

            var receivePipe = CreateReceivePipe(receiveEndpointBuilder);

            _sendEndpointProvider = CreateSendEndpointProvider(receiveEndpointBuilder);
            _publishEndpointProvider = CreatePublishEndpointProvider(receiveEndpointBuilder);

            var inMemoryBusBuilder = builder as InMemoryBusBuilder;
            if (inMemoryBusBuilder == null)
                throw new ArgumentException("The bus builder is expected to by an InMemoryBusBuilder", nameof(inMemoryBusBuilder));

            var transport = inMemoryBusBuilder.InMemoryHost.GetReceiveTransport(_queueName, _transportConcurrencyLimit, _sendEndpointProvider,
                _publishEndpointProvider);

            var inMemoryHost = inMemoryBusBuilder.InMemoryHost as InMemoryHost;
            if (inMemoryHost == null)
                throw new ConfigurationException("Must be an InMemoryHost");

            inMemoryHost.ReceiveEndpoints.Add(_queueName, new ReceiveEndpoint(transport, receivePipe));
        }
 public Settings(string pathMatch, IMessageSerializer messageSerializer, ISendEndpointProvider sendEndpointProvider,
     IPublishEndpointProvider publishEndpointProvider)
 {
     PathMatch = pathMatch;
     MessageSerializer = messageSerializer;
     SendEndpointProvider = sendEndpointProvider;
     PublishEndpointProvider = publishEndpointProvider;
 }
Esempio n. 48
0
        public IMessageDeserializer GetMessageDeserializer(ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
        {
            IMessageDeserializer[] deserializers =
                _deserializerFactories.Values.Select(x => x(sendEndpointProvider, publishEndpointProvider)).ToArray();

            return new SupportedMessageDeserializers(deserializers);
        }
 public ProtocolBuffersMessageDeserializer(ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider)
 {
     _sendEndpointProvider = sendEndpointProvider;
     _publishEndpointProvider = publishEndpointProvider;
 }
 IMessageDeserializer CreateDeserializer(ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpoint)
 {
     return new EncryptedMessageDeserializer(BsonMessageSerializer.Deserializer, sendEndpointProvider, publishEndpoint,
         _streamProvider);
 }