public void Start(CancellationToken cancellationToken) { if (_endpointHandle != null) { return; } _endpointHandle = _endpoint.Start(cancellationToken); }
public Handle(ReceiveEndpointHandle endpointHandle, IReceiveEndpoint receiveEndpoint, Task <ReceiveEndpointReady> ready, Action onStopped, params ConnectHandle[] handles) { _endpointHandle = endpointHandle; _onStopped = onStopped; _handles = handles; ReceiveEndpoint = receiveEndpoint; Ready = ready; }
public async Task <BusHandle> StartAsync(CancellationToken cancellationToken) { if (_busHandle != null) { _log.Warn($"The bus was already started, additional Start attempts are ignored: {Address}"); return(_busHandle); } await _busObservable.PreStart(this).ConfigureAwait(false); Handle busHandle = null; var endpoints = new List <ReceiveEndpointHandle>(); var hosts = new List <HostHandle>(); var observers = new List <ConnectHandle>(); var busReady = new BusReady(_receiveEndpoints); try { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting bus hosts..."); } foreach (IBusHostControl host in _hosts) { HostHandle hostHandle = host.Start(); hosts.Add(hostHandle); } if (_log.IsDebugEnabled) { _log.DebugFormat("Starting receive endpoints..."); } foreach (IReceiveEndpoint endpoint in _receiveEndpoints) { ConnectHandle observerHandle = endpoint.ConnectReceiveObserver(_receiveObservers); observers.Add(observerHandle); ReceiveEndpointHandle handle = endpoint.Start(); endpoints.Add(handle); } busHandle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady); await busHandle.Ready.WithCancellation(cancellationToken).ConfigureAwait(false); await _busObservable.PostStart(this, busReady.Ready).ConfigureAwait(false); _busHandle = busHandle; return(_busHandle); } catch (Exception ex) { try { if (busHandle != null) { busHandle.Stop(TimeSpan.FromSeconds(60)); } else { var handle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady); handle.Stop(TimeSpan.FromSeconds(60)); } } catch (Exception stopException) { _log.Error("Failed to stop partially created bus", stopException); } await _busObservable.StartFaulted(this, ex).ConfigureAwait(false); throw; } }
BusHandle IBusControl.Start() { if (_busHandle != null) { _log.Warn($"The bus was already started, additional Start attempts are ignored: {Address}"); return(_busHandle); } TaskUtil.Await(() => _busObservable.PreStart(this)); Exception exception = null; var endpoints = new List <ReceiveEndpointHandle>(); var hosts = new List <HostHandle>(); var observers = new List <ConnectHandle>(); var busReady = new BusReady(_receiveEndpoints); try { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting bus hosts..."); } foreach (IBusHostControl host in _hosts) { try { HostHandle hostHandle = host.Start(); hosts.Add(hostHandle); } catch (Exception ex) { exception = ex; } } if (_log.IsDebugEnabled) { _log.DebugFormat("Starting receive endpoints..."); } foreach (IReceiveEndpoint endpoint in _receiveEndpoints) { try { ConnectHandle observerHandle = endpoint.ConnectReceiveObserver(_receiveObservers); observers.Add(observerHandle); ReceiveEndpointHandle handle = endpoint.Start(); endpoints.Add(handle); } catch (Exception ex) { exception = ex; } } } catch (Exception ex) { exception = ex; } if (exception != null) { try { var handle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady); handle.Stop(TimeSpan.FromSeconds(60)); } catch (Exception ex) { _log.Error("Failed to stop partially created bus", ex); } TaskUtil.Await(() => _busObservable.StartFaulted(this, exception)); throw new MassTransitException("The service bus could not be started.", exception); } _busHandle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady); TaskUtil.Await(() => _busObservable.PostStart(this, busReady.Ready)); return(_busHandle); }