Exemplo n.º 1
0
        /// <summary>
        /// Creates an instance of the ServiceBus, which implements IServiceBus. This is normally
        /// not called and should be created using the ServiceBusConfigurator to ensure proper defaults
        /// and operation.
        /// </summary>
        public ServiceBus(IEndpoint endpointToListenOn,
                          IObjectBuilder objectBuilder,
                          IEndpointFactory endpointFactory)
        {
            ReceiveTimeout = TimeSpan.FromSeconds(3);
            endpointToListenOn.MustNotBeNull("endpointToListenOn", "This parameter cannot be null");
            objectBuilder.MustNotBeNull("objectBuilder", "This parameter cannot be null");
            endpointFactory.MustNotBeNull("endpointFactory", "This parameter cannot be null");

            Endpoint        = endpointToListenOn;
            ObjectBuilder   = objectBuilder;
            EndpointFactory = endpointFactory;

            _eventAggregator      = PipeSegment.New();
            _eventAggregatorScope = _eventAggregator.NewSubscriptionScope();

            _serviceContainer = new ServiceContainer(this);

            OutboundPipeline = MessagePipelineConfigurator.CreateDefault(ObjectBuilder, this);

            InboundPipeline = MessagePipelineConfigurator.CreateDefault(ObjectBuilder, this);
            InboundPipeline.Configure(x => { _unsubscribeEventDispatchers += x.Register(new InboundOutboundSubscriptionBinder(OutboundPipeline, Endpoint)); });

            PoisonEndpoint = new PoisonEndpointDecorator(new NullEndpoint());

            ControlBus = this;

            InitializePerformanceCounters();
        }
Exemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                if (_consumerPool != null)
                {
                    _consumerPool.Stop();
                    _consumerPool.Dispose();
                    _consumerPool = null;
                }

                if (_serviceContainer != null)
                {
                    _serviceContainer.Stop();
                    _serviceContainer.Dispose();
                    _serviceContainer = null;
                }

                if (ControlBus != this)
                {
                    ControlBus.Dispose();
                }

                _unsubscribeEventDispatchers();

                InboundPipeline.Dispose();
                InboundPipeline = null;

                OutboundPipeline.Dispose();
                OutboundPipeline = null;

                if (_eventAggregatorScope != null)
                {
                    _eventAggregatorScope.Dispose();
                    _eventAggregatorScope = null;
                }

                _eventAggregator = null;

                Endpoint = null;

                if (_counters != null)
                {
                    _counters.Dispose();
                    _counters = null;
                }

                if (PoisonEndpoint != null)
                {
                    PoisonEndpoint = null;
                }
            }
            _disposed = true;
        }
Exemplo n.º 3
0
        public void Inspect(DiagnosticsProbe probe)
        {
            new StandardDiagnosticsInfo().WriteCommonItems(probe);

            probe.Add("mt.version", typeof(IServiceBus).Assembly.GetName().Version);
            probe.Add("mt.receive_from", Endpoint.Address);
            probe.Add("mt.control_bus", ControlBus.Endpoint.Address);
            probe.Add("mt.max_consumer_threads", MaximumConsumerThreads);
            probe.Add("mt.concurrent_receive_threads", ConcurrentReceiveThreads);
            probe.Add("mt.receive_timeout", ReceiveTimeout);

            EndpointCache.Inspect(probe);
            _serviceContainer.Inspect(probe);

            OutboundPipeline.View(pipe => probe.Add("zz.mt.outbound_pipeline", pipe));
            InboundPipeline.View(pipe => probe.Add("zz.mt.inbound_pipeline", pipe));
        }
Exemplo n.º 4
0
 public UnsubscribeAction SubscribeConsumer <T>(Func <T, Action <T> > getConsumerAction)
     where T : class
 {
     return(InboundPipeline.Subscribe <T>(getConsumerAction));
 }
Exemplo n.º 5
0
        public UnsubscribeAction Subscribe <TComponent>() where TComponent : class
        {
            UnsubscribeAction result = InboundPipeline.Subscribe <TComponent>();

            return(result);
        }
Exemplo n.º 6
0
        public UnsubscribeAction Subscribe <T>(T consumer) where T : class
        {
            UnsubscribeAction result = InboundPipeline.Subscribe(consumer);

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a message handler to the service bus for handling a specific type of message
        /// </summary>
        /// <typeparam name="T">The message type to handle, often inferred from the callback specified</typeparam>
        /// <param name="callback">The callback to invoke when messages of the specified type arrive on the service bus</param>
        /// <param name="condition">A condition predicate to filter which messages are handled by the callback</param>
        public UnsubscribeAction Subscribe <T>(Action <T> callback, Predicate <T> condition) where T : class
        {
            UnsubscribeAction result = InboundPipeline.Subscribe(callback, condition);

            return(result);
        }
Exemplo n.º 8
0
 public UnsubscribeAction Configure(Func <IInboundPipelineConfigurator, UnsubscribeAction> configure)
 {
     return(InboundPipeline.Configure(configure));
 }