public Handle(Task <MessagingFactory> messagingFactoryTask, Lazy <Task <MessagingFactory> > sessionFactory, ServiceBusHostSettings settings, TaskSupervisor supervisor) { _messagingFactoryTask = messagingFactoryTask; _sessionFactory = sessionFactory; _settings = settings; _supervisor = supervisor; }
async void Receiver(TaskSupervisor supervisor, IPipe <ConnectionContext> connectionPipe) { await _connectionRetryPolicy.RetryUntilCancelled(async() => { if (_log.IsDebugEnabled) { _log.DebugFormat("Connecting receive transport: {0}", _host.Settings.GetInputAddress(_settings.QueueDescription)); } var context = new ServiceBusConnectionContext(_host, supervisor.StopToken); try { await connectionPipe.Send(context).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.ErrorFormat("Azure Service Bus connection failed: {0}", ex.Message); } var inputAddress = context.GetQueueAddress(_settings.QueueDescription); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } }, supervisor.StoppingToken).ConfigureAwait(false); }
public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { if (_log.IsDebugEnabled) _log.DebugFormat("Starting receive transport: {0}", new Uri(_host.Settings.ServiceUri, _settings.QueueDescription.Path)); var supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusReceiveTransport>.ShortName} - {_host.Settings.GetInputAddress(_settings.QueueDescription)}"); IPipe<ConnectionContext> connectionPipe = Pipe.New<ConnectionContext>(x => { x.UseFilter(new PrepareReceiveQueueFilter(_settings, _subscriptionSettings)); if (_settings.QueueDescription.RequiresSession) { x.UseFilter(new MessageSessionReceiverFilter(receivePipe, _receiveObservers, _endpointObservers, supervisor)); } else { x.UseFilter(new MessageReceiverFilter(receivePipe, _receiveObservers, _endpointObservers, supervisor)); } }); Receiver(connectionPipe, supervisor); return new Handle(supervisor); }
public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting receive transport: {0}", new Uri(_host.Settings.ServiceUri, _settings.QueueDescription.Path)); } var supervisor = new TaskSupervisor(); var connectionPipe = Pipe.New <ConnectionContext>(x => { x.UseFilter(new PrepareReceiveQueueFilter(_settings, _subscriptionSettings)); if (_settings.QueueDescription.RequiresSession) { x.UseFilter(new MessageSessionReceiverFilter(receivePipe, _receiveObservers, _endpointObservers, supervisor)); } else { x.UseFilter(new MessageReceiverFilter(receivePipe, _receiveObservers, _endpointObservers, supervisor)); } }); Receiver(supervisor, connectionPipe); return(new Handle(supervisor)); }
private void Init(string ipStart = "127.0.0.1", string ipEnd = "127.0.0.1", int portStart = 80, int portEnd = 80, int timeOut = 30, int taskMaxNum = 10) { if (!reg.IsMatch(ipStart) || !reg.IsMatch(ipEnd))//匹配正确IP { throw new ArgumentException("Ip地址错误"); } if (IpHelper.IpToInt64(ipStart) > IpHelper.IpToInt64(ipEnd)) { throw new ArgumentException("Ip地址范围错误"); } if (portStart <= 0 || portEnd <= 0 || portEnd < portStart) { throw new ArgumentException("端口范围不正确"); } this.IpStart = ipStart; this.IpEnd = ipEnd; this.PortStart = portStart; this.PortEnd = portEnd; this.TimeOut = timeOut <= 0 ? 10 : timeOut; this.TaskMaxNum = taskMaxNum <= 0 ? 10 : taskMaxNum; TaskSupervisor = new TaskEx.TaskSupervisor(this.TaskMaxNum); }
async void Receiver(IPipe<ConnectionContext> transportPipe, TaskSupervisor supervisor) { await Repeat.UntilCancelled(supervisor.StopToken, async () => { try { await _host.ConnectionCache.Send(transportPipe, supervisor.StopToken).ConfigureAwait(false); } catch (RabbitMqConnectionException ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("RabbitMQ connection failed: {0}", ex.Message); var inputAddress = _host.Settings.GetInputAddress(_settings); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("RabbitMQ receive transport failed: {0}", ex.Message); var inputAddress = _host.Settings.GetInputAddress(_settings); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } }).ConfigureAwait(false); }
public ServiceBusHost(ServiceBusHostSettings settings) { Settings = settings; _messagingFactory = new Lazy <Task <MessagingFactory> >(CreateMessagingFactory); _sessionMessagingFactory = new Lazy <Task <MessagingFactory> >(CreateNetMessagingFactory); _namespaceManager = new Lazy <NamespaceManager>(CreateNamespaceManager); _rootNamespaceManager = new Lazy <NamespaceManager>(CreateRootNamespaceManager); MessageNameFormatter = new ServiceBusMessageNameFormatter(); _receiveEndpoints = new ReceiveEndpointCollection(); _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {Settings.ServiceUri}"); RetryPolicy = Retry.CreatePolicy(x => { x.Ignore <MessagingEntityNotFoundException>(); x.Ignore <MessagingEntityAlreadyExistsException>(); x.Ignore <MessageNotFoundException>(); x.Ignore <MessageSizeExceededException>(); x.Ignore <NoMatchingSubscriptionException>(); x.Ignore <TransactionSizeExceededException>(); x.Handle <ServerBusyException>(exception => exception.IsTransient || exception.IsWrappedExceptionTransient()); x.Handle <MessagingException>(exception => exception.IsTransient || exception.IsWrappedExceptionTransient()); x.Handle <TimeoutException>(); x.Intervals(100, 500, 1000, 5000, 10000); }); }
public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var inputAddress = _settings.GetInputAddress(_host.Settings.ServiceUri); if (_log.IsDebugEnabled) { _log.DebugFormat("Starting receive transport: {0}", inputAddress); } var supervisor = new TaskSupervisor($"{TypeMetadataCache<ReceiveTransport>.ShortName} - {inputAddress}"); IPipe <NamespaceContext> pipe = Pipe.New <NamespaceContext>(x => { x.UseRetry(r => r.SetRetryPolicy(_ => _host.RetryPolicy)); for (var i = 0; i < _specifications.Length; i++) { x.AddPipeSpecification(_specifications[i]); } }); Receiver(pipe, supervisor); return(new Handle(supervisor)); }
async void Receiver(IPipe <ConnectionContext> transportPipe, TaskSupervisor supervisor) { await Repeat.UntilCancelled(supervisor.StopToken, async() => { try { await _host.ConnectionCache.Send(transportPipe, supervisor.StopToken).ConfigureAwait(false); } catch (RabbitMqConnectionException ex) { if (_log.IsErrorEnabled) { _log.ErrorFormat("RabbitMQ connection failed: {0}", ex.Message); } var inputAddress = _host.Settings.GetInputAddress(_settings); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.ErrorFormat("RabbitMQ receive transport failed: {0}", ex.Message); } var inputAddress = _host.Settings.GetInputAddress(_settings); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } }).ConfigureAwait(false); }
public async Task X() { var sup = new TaskSupervisor("test"); var cache = new OwinHostCache(new ConfigurationHostSettings("http", "localhost", 8080, HttpMethod.Post), sup); await cache.Send(Pipe.Empty<OwinHostContext>(), default(CancellationToken)); await sup.Stop("test"); }
public async Task X() { var sup = new TaskSupervisor("test"); var cache = new OwinHostCache(new ConfigurationHostSettings("http", "localhost", 8080, HttpMethod.Post), sup); await cache.Send(Pipe.Empty <OwinHostContext>(), default(CancellationToken)); await sup.Stop("test"); }
/// <summary> /// 构造函数 /// </summary> /// <param name="url">初始的URL</param> /// <param name="maxTaskNum">最大任务数</param> /// <param name="imageQueue">图片队列</param> public AnalysisBehaviorBusiness(string url, int maxTaskNum, Queue imageQueue) { //// 添加第一个URL WaitUrlQueue.Enqueue(url); //// 初始化任务管理器 TaskSupervisor = new TaskSupervisor(maxTaskNum); WaitImageUrlQueue = imageQueue; ExistUrlList = new List <string>(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="url">初始的URL</param> /// <param name="maxTaskNum">最大任务数</param> /// <param name="imageQueue">图片队列</param> public HttpAnalysisBehavior(string url, int maxTaskNum, ConcurrentQueue <string> imageQueue) { //// 添加第一个URL WaitUrlQueue.Enqueue(url); //// 初始化任务管理器 TaskSupervisor = new TaskSupervisor(maxTaskNum); WaitImageUrlQueue = imageQueue; ExistUrlList = new ConcurrentBag <string>(); }
public ServiceBusNamespaceContext(IServiceBusHost host, IReceiveObserver receiveObserver, IReceiveTransportObserver receiveTransportObserver, TaskSupervisor supervisor) : base(new PayloadCache(), supervisor.StoppingToken) { _host = host; _receiveObserver = receiveObserver; _receiveTransportObserver = receiveTransportObserver; _supervisor = supervisor; }
public InMemoryTransport(Uri inputAddress, int concurrencyLimit) { _inputAddress = inputAddress; _sendObservable = new SendObservable(); _receiveObservable = new ReceiveObservable(); _endpointObservable = new ReceiveEndpointObservable(); _supervisor = new TaskSupervisor(); _scheduler = new QueuedTaskScheduler(TaskScheduler.Default, concurrencyLimit); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor(); var pipe = Pipe.New <ConnectionContext>( x => x.RabbitMqConsumer(receivePipe, _settings, _receiveObservers, _endpointObservers, _exchangeBindings, supervisor)); Receiver(pipe, supervisor); return(new Handle(supervisor)); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor(); var pipe = Pipe.New<ConnectionContext>( x => x.RabbitMqConsumer(receivePipe, _settings, _receiveObservers, _endpointObservers, _exchangeBindings, supervisor)); Receiver(pipe, supervisor); return new Handle(supervisor); }
public ServiceBusHost(ServiceBusHostSettings settings) { _settings = settings; _messagingFactory = new Lazy<Task<MessagingFactory>>(CreateMessagingFactory); _sessionMessagingFactory = new Lazy<Task<MessagingFactory>>(CreateNetMessagingFactory); _namespaceManager = new Lazy<Task<NamespaceManager>>(CreateNamespaceManager); _rootNamespaceManager = new Lazy<Task<NamespaceManager>>(CreateRootNamespaceManager); _messageNameFormatter = new ServiceBusMessageNameFormatter(); _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {_settings.ServiceUri}"); }
public RabbitMqHost(RabbitMqHostSettings hostSettings) { _hostSettings = hostSettings; var exceptionFilter = Retry.Selected<RabbitMqConnectionException>(); _connectionRetryPolicy = exceptionFilter.Exponential(1000, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)); _supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqHost>.ShortName} - {_hostSettings.ToDebugString()}"); _connectionCache = new RabbitMqConnectionCache(hostSettings, _supervisor); }
public RabbitMqHost(RabbitMqHostSettings hostSettings) { _hostSettings = hostSettings; var exceptionFilter = Retry.Selected <RabbitMqConnectionException>(); _connectionRetryPolicy = exceptionFilter.Exponential(1000, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)); _supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqHost>.ShortName} - {_hostSettings.ToDebugString()}"); _connectionCache = new RabbitMqConnectionCache(hostSettings, _supervisor); }
public ServiceBusHost(ServiceBusHostSettings settings) { _settings = settings; _messagingFactory = new Lazy <Task <MessagingFactory> >(CreateMessagingFactory); _sessionMessagingFactory = new Lazy <Task <MessagingFactory> >(CreateNetMessagingFactory); _namespaceManager = new Lazy <Task <NamespaceManager> >(CreateNamespaceManager); _rootNamespaceManager = new Lazy <Task <NamespaceManager> >(CreateRootNamespaceManager); _messageNameFormatter = new ServiceBusMessageNameFormatter(); _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {_settings.ServiceUri}"); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor(); IPipe <ConnectionContext> pipe = Pipe.New <ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveEndpointObservable, _bindings, supervisor, _mediator); }); Receiver(pipe, supervisor); return(new Handle(supervisor)); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeCache<RabbitMqReceiveTransport>.ShortName} - {_inputAddress}"); IPipe <ConnectionContext> pipe = Pipe.New <ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveTransportObservable, supervisor, _managementPipe, _host, _topology); }); Task.Factory.StartNew(() => Receiver(pipe, supervisor), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); return(new Handle(supervisor)); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqReceiveTransport>.ShortName} - {_host.Settings.GetInputAddress(_settings)}"); IPipe<ConnectionContext> pipe = Pipe.New<ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveEndpointObservable, _bindings, supervisor, _managementPipe); }); Receiver(pipe, supervisor); return new Handle(supervisor); }
public HttpHost(HttpHostSettings hostSettings) { _settings = hostSettings; //exception Filter ReceiveEndpoints = new ReceiveEndpointCollection(); //connection retry policy _supervisor = new TaskSupervisor($"{TypeMetadataCache<HttpHost>.ShortName} - {Settings.Host}"); _owinHostCache = new OwinHostCache(Settings, _supervisor); }
public async Task Should_fault_if_not_completed() { var supervisor = new TaskSupervisor("test"); var stopwatch = Stopwatch.StartNew(); var participant = supervisor.CreateParticipant("testA"); Assert.Throws <OperationCanceledException>(async() => await supervisor.Completed.WithTimeout(1000)); stopwatch.Stop(); stopwatch.Elapsed.ShouldBeGreaterThan(TimeSpan.FromMilliseconds(750)); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqReceiveTransport>.ShortName} - {_host.Settings.GetInputAddress(_settings)}"); IPipe <ConnectionContext> pipe = Pipe.New <ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveEndpointObservable, _bindings, supervisor, _mediator); }); Receiver(pipe, supervisor); return(new Handle(supervisor)); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor(); IPipe<ConnectionContext> pipe = Pipe.New<ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveEndpointObservable, _bindings, supervisor, _mediator); }); Receiver(pipe, supervisor); return new Handle(supervisor); }
public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeMetadataCache<HttpReceiveTransport>.ShortName} - {_host.Settings.GetInputAddress()}"); IPipe <OwinHostContext> hostPipe = Pipe.New <OwinHostContext>(cxt => { cxt.HttpConsumer(receivePipe, _host.Settings, _receiveSettings, _receiveObservable, _receiveTransportObservable, supervisor, _sendPipe); }); var hostTask = _host.OwinHostCache.Send(hostPipe, supervisor.StoppingToken); return(new Handle(supervisor, hostTask)); }
public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeMetadataCache<HttpReceiveTransport>.ShortName} - {_host.Settings.GetInputAddress()}"); IPipe<OwinHostContext> hostPipe = Pipe.New<OwinHostContext>(cxt => { cxt.HttpConsumer(receivePipe, _host.Settings, _receiveSettings, _receiveObservable, _receiveTransportObservable, supervisor, _sendPipe); }); var hostTask = _host.OwinHostCache.Send(hostPipe, supervisor.StoppingToken); return new Handle(supervisor, hostTask); }
public InMemoryTransport(Uri inputAddress, int concurrencyLimit) { _inputAddress = inputAddress; _sendObservable = new SendObservable(); _receiveObservable = new ReceiveObservable(); _endpointObservable = new ReceiveEndpointObservable(); _supervisor = new TaskSupervisor($"{TypeMetadataCache<InMemoryTransport>.ShortName} - {_inputAddress}"); _participant = _supervisor.CreateParticipant($"{TypeMetadataCache<InMemoryTransport>.ShortName} - {_inputAddress}"); _scheduler = new LimitedConcurrencyLevelTaskScheduler(concurrencyLimit); }
/// <summary> /// Start the receive transport, returning a Task that can be awaited to signal the transport has /// completely shutdown once the cancellation token is cancelled. /// </summary> /// <param name="receivePipe"></param> /// <returns>A task that is completed once the transport is shut down</returns> public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var supervisor = new TaskSupervisor($"{TypeCache<RabbitMqReceiveTransport>.ShortName} - {_inputAddress}"); IPipe <ConnectionContext> pipe = Pipe.New <ConnectionContext>(x => { x.RabbitMqConsumer(receivePipe, _settings, _receiveObservable, _receiveTransportObservable, _bindings, supervisor, _managementPipe, _sendEndpointProvider, _publishEndpointProvider, _host); }); Receiver(pipe, supervisor); return(new Handle(supervisor)); }
public InMemoryReceiveTransport(Uri inputAddress, IInMemoryQueue queue, IReceiveEndpointTopology topology) { _inputAddress = inputAddress; _queue = queue; _topology = topology; _receiveObservable = new ReceiveObservable(); _transportObservable = new ReceiveTransportObservable(); _tracker = new DeliveryTracker(HandleDeliveryComplete); _supervisor = new TaskSupervisor($"{TypeMetadataCache<InMemoryReceiveTransport>.ShortName} - {_inputAddress}"); _participant = _supervisor.CreateParticipant($"{TypeMetadataCache<InMemoryReceiveTransport>.ShortName} - {_inputAddress}"); }
public ReceiveTransportHandle Start(IPipe <ReceiveContext> receivePipe) { var inputAddress = _settings.GetInputAddress(_host.Settings.ServiceUri, _settings.Path); if (_log.IsDebugEnabled) { _log.DebugFormat("Starting receive transport: {0}", inputAddress); } var supervisor = new TaskSupervisor($"{TypeMetadataCache<ReceiveTransport>.ShortName} - {inputAddress}"); Task.Factory.StartNew(() => Receiver(_pipe, supervisor), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); return(new Handle(supervisor)); }
public ServiceBusHost(ServiceBusHostSettings settings) { Settings = settings; _messagingFactory = new Lazy <Task <MessagingFactory> >(CreateMessagingFactory); _sessionMessagingFactory = new Lazy <Task <MessagingFactory> >(CreateNetMessagingFactory); _namespaceManager = new Lazy <NamespaceManager>(CreateNamespaceManager); _rootNamespaceManager = new Lazy <NamespaceManager>(CreateRootNamespaceManager); MessageNameFormatter = new ServiceBusMessageNameFormatter(); _receiveEndpoints = new ReceiveEndpointCollection(); _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {Settings.ServiceUri}"); RetryPolicy = Retry.Selected <ServerBusyException, TimeoutException>().Intervals(100, 500, 1000, 5000, 10000); }
public RabbitMqHost(RabbitMqHostSettings settings, IRabbitMqHostTopology topology) { _settings = settings; _topology = topology; var exceptionFilter = Retry.Selected <RabbitMqConnectionException>(); ReceiveEndpoints = new ReceiveEndpointCollection(); _connectionRetryPolicy = exceptionFilter.Exponential(1000, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)); _supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqHost>.ShortName} - {_settings.ToDebugString()}"); _connectionCache = new RabbitMqConnectionCache(settings, _topology, _supervisor); }
public async Task Should_complete_if_participant_is_completed() { var supervisor = new TaskSupervisor("test"); var stopwatch = Stopwatch.StartNew(); var participant = supervisor.CreateParticipant("testA"); Task.Delay(100) .ContinueWith(x => participant.SetComplete()); await supervisor.Completed.WithTimeout(1000); stopwatch.Stop(); stopwatch.Elapsed.ShouldBeGreaterThan(TimeSpan.FromMilliseconds(75)); }
public InMemoryTransport(Uri inputAddress, int concurrencyLimit, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider) { _inputAddress = inputAddress; _sendEndpointProvider = sendEndpointProvider; _publishEndpointProvider = publishEndpointProvider; _sendObservable = new SendObservable(); _receiveObservable = new ReceiveObservable(); _transportObservable = new ReceiveTransportObservable(); _tracker = new DeliveryTracker(HandleDeliveryComplete); _supervisor = new TaskSupervisor($"{TypeMetadataCache<InMemoryTransport>.ShortName} - {_inputAddress}"); _participant = _supervisor.CreateParticipant($"{TypeMetadataCache<InMemoryTransport>.ShortName} - {_inputAddress}"); _scheduler = new LimitedConcurrencyLevelTaskScheduler(concurrencyLimit); }
async void Receiver(IPipe <NamespaceContext> pipe, TaskSupervisor supervisor) { Uri inputAddress = _settings.GetInputAddress(_host.Settings.ServiceUri); try { await _host.RetryPolicy.RetryUntilCancelled(async() => { if (_log.IsDebugEnabled) { _log.DebugFormat("Connecting receive transport: {0}", inputAddress); } var context = new ServiceBusNamespaceContext(_host, _receiveObservers, _endpointObservers, supervisor); try { await pipe.Send(context).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (OperationCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error($"Azure Service Bus receiver faulted: {inputAddress}", ex); } await _endpointObservers.Faulted(new ReceiveTransportFaultedEvent(inputAddress, ex)).ConfigureAwait(false); throw; } }, supervisor.StoppingToken).ConfigureAwait(false); } catch (Exception ex) { _log.Error($"Unhandled exception on Receiver: {inputAddress}", ex); } }
public ReceiveTransportHandle Start(IPipe<ReceiveContext> receivePipe) { var inputAddress = _settings.GetInputAddress(_host.Settings.ServiceUri); if (_log.IsDebugEnabled) _log.DebugFormat("Starting receive transport: {0}", inputAddress); var supervisor = new TaskSupervisor($"{TypeMetadataCache<ReceiveTransport>.ShortName} - {inputAddress}"); IPipe<NamespaceContext> pipe = Pipe.New<NamespaceContext>(x => { x.UseRetry(r => r.SetRetryPolicy(_ => _host.RetryPolicy)); for (var i = 0; i < _specifications.Length; i++) { x.AddPipeSpecification(_specifications[i]); } }); Receiver(pipe, supervisor); return new Handle(supervisor); }
public Handle(Task<MessagingFactory> messagingFactoryTask, Lazy<Task<MessagingFactory>> sessionFactory, ServiceBusHostSettings settings, TaskSupervisor supervisor) { _messagingFactoryTask = messagingFactoryTask; _sessionFactory = sessionFactory; _settings = settings; _supervisor = supervisor; }
public Handle(TaskSupervisor supervisor) { _supervisor = supervisor; }
async void Receiver(IPipe<ConnectionContext> connectionPipe, TaskSupervisor supervisor) { try { await _connectionRetryPolicy.RetryUntilCancelled(async () => { if (_log.IsDebugEnabled) _log.DebugFormat("Connecting receive transport: {0}", _host.Settings.GetInputAddress(_settings.QueueDescription)); var context = new ServiceBusConnectionContext(_host, supervisor.StoppedToken); try { await connectionPipe.Send(context).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("Azure Service Bus connection failed: {0}", ex.Message); var inputAddress = context.GetQueueAddress(_settings.QueueDescription); await _endpointObservers.Faulted(new Faulted(inputAddress, ex)).ConfigureAwait(false); } }, supervisor.StoppingToken).ConfigureAwait(false); } catch (TaskCanceledException) { } }
async void Receiver(IPipe<ConnectionContext> transportPipe, TaskSupervisor supervisor) { try { await _host.ConnectionRetryPolicy.RetryUntilCancelled(async () => { try { await _host.ConnectionCache.Send(transportPipe, supervisor.StoppingToken) .ConfigureAwait(false); } catch (RabbitMqConnectionException ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("RabbitMQ connection failed: {0}", ex.Message); await _receiveTransportObservable.Faulted(new ReceiveTransportFaultedEvent(_inputAddress, ex)).ConfigureAwait(false); throw; } catch (TaskCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("RabbitMQ receive transport failed: {0}", ex.Message); await _receiveTransportObservable.Faulted(new ReceiveTransportFaultedEvent(_inputAddress, ex)).ConfigureAwait(false); throw; } }, supervisor.StoppingToken).ConfigureAwait(false); } catch (TaskCanceledException) { } }
async void Receiver(IPipe<NamespaceContext> pipe, TaskSupervisor supervisor) { var inputAddress = _settings.GetInputAddress(_host.Settings.ServiceUri); try { await _host.RetryPolicy.RetryUntilCancelled(async () => { if (_log.IsDebugEnabled) _log.DebugFormat("Connecting receive transport: {0}", inputAddress); var context = new ServiceBusNamespaceContext(_host, _receiveObservers, _endpointObservers, supervisor); try { await pipe.Send(context).ConfigureAwait(false); } catch (TaskCanceledException) { } catch (OperationCanceledException) { } catch (Exception ex) { if (_log.IsErrorEnabled) _log.Error($"Azure Service Bus receiver faulted: {inputAddress}", ex); await _endpointObservers.Faulted(new ReceiveTransportFaultedEvent(inputAddress, ex)).ConfigureAwait(false); throw; } }, supervisor.StoppingToken).ConfigureAwait(false); } catch (Exception ex) { _log.Error($"Unhandled exception on Receiver: {inputAddress}", ex); } }
public Handle(TaskSupervisor supervisor, Task connectionTask) { _supervisor = supervisor; _connectionTask = connectionTask; }
public Handle(Task connectionTask, TaskSupervisor supervisor) { _connectionTask = connectionTask; _supervisor = supervisor; }