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; }
/// <summary> /// Publishes a message to all subscribed consumers for the message type /// </summary> /// <typeparam name="T">The type of the message</typeparam> /// <param name="message">The messages to be published</param> /// <param name="contextCallback">The callback to perform operations on the context</param> public void Publish <T>(T message, Action <IPublishContext <T> > contextCallback) where T : class { PublishContext <T> context = ContextStorage.CreatePublishContext(message); context.SetSourceAddress(Endpoint.Address.Uri); contextCallback(context); IList <Exception> exceptions = new List <Exception>(); int publishedCount = 0; foreach (var consumer in OutboundPipeline.Enumerate(context)) { try { consumer(context); publishedCount++; } catch (Exception ex) { _log.Error(string.Format("'{0}' threw an exception publishing message '{1}'", consumer.GetType().FullName, message.GetType().FullName), ex); exceptions.Add(ex); } } context.Complete(); if (publishedCount == 0) { context.NotifyNoSubscribers(); } _eventChannel.Send(new MessagePublished { MessageType = typeof(T), ConsumerCount = publishedCount, Duration = context.Duration, }); if (exceptions.Count > 0) { throw new PublishException(typeof(T), exceptions); } }
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)); }
/// <summary> /// Publishes a message to all subscribed consumers for the message type /// </summary> /// <typeparam name="T">The type of the message</typeparam> /// <param name="message">The messages to be published</param> public void Publish <T>(T message) where T : class { Stopwatch publishDuration = Stopwatch.StartNew(); IOutboundMessageContext context = OutboundMessage.Context; context.SetSourceAddress(Endpoint.Uri); context.SetMessageType(typeof(T)); int publishedCount = 0; foreach (var consumer in OutboundPipeline.Enumerate(message)) { try { consumer(message); publishedCount++; } catch (Exception ex) { _log.Error(string.Format("'{0}' threw an exception publishing message '{1}'", consumer.GetType().FullName, message.GetType().FullName), ex); } } publishDuration.Stop(); if (publishedCount == 0) { context.NotifyNoSubscribers(message); } _eventAggregator.Send(new MessagePublished { MessageType = typeof(T), ConsumerCount = publishedCount, Duration = publishDuration.Elapsed, }); context.Reset(); }