public virtual async Task Start(CancellationToken cancellationToken = default) { _received = new BusTestReceiveObserver(TestInactivityTimeout); _received.ConnectInactivityObserver(InactivityObserver); _consumed = new BusTestConsumeObserver(TestTimeout, InactivityToken); _consumed.ConnectInactivityObserver(InactivityObserver); _published = new BusTestPublishObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _published.ConnectInactivityObserver(InactivityObserver); _sent = new BusTestSendObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _sent.ConnectInactivityObserver(InactivityObserver); PreCreateBus?.Invoke(this); BusControl = CreateBus(); ConnectObservers(BusControl); _busHandle = await BusControl.StartAsync(cancellationToken).ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(BusControl.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); InputQueueSendEndpoint.ConnectSendObserver(_sent); BusControl.ConnectConsumeObserver(_consumed); BusControl.ConnectPublishObserver(_published); BusControl.ConnectReceiveObserver(_received); BusControl.ConnectSendObserver(_sent); }
public async Task StartAsync(CancellationToken cancellationToken = new CancellationToken()) { var startTask = Task.CompletedTask; lock (this) { if (!IsBusControlCreated) { BusControl = Bus.Factory.CreateUsingAzureServiceBus(cfg => { var host = cfg.Host(HostConfiguration.ServiceUri, HostConfiguration.ConfigureHost); foreach (var queue in QueueConfigurations) { cfg.ReceiveEndpoint( host, queue.Key, c => { foreach (var action in queue.Value) { action(c, host); } }); } }); IsBusControlCreated = true; startTask = BusControl.StartAsync(cancellationToken); } } await startTask; }