/// <summary>
        /// Creates the worker factory
        /// </summary>
        public ThreadPoolWorkerFactory(ITransport transport, IRebusLoggerFactory rebusLoggerFactory, IPipeline pipeline, IPipelineInvoker pipelineInvoker, Options options, Func<RebusBus> busGetter, BusLifetimeEvents busLifetimeEvents, ISyncBackoffStrategy backoffStrategy)
        {
            if (transport == null) throw new ArgumentNullException(nameof(transport));
            if (rebusLoggerFactory == null) throw new ArgumentNullException(nameof(rebusLoggerFactory));
            if (pipeline == null) throw new ArgumentNullException(nameof(pipeline));
            if (pipelineInvoker == null) throw new ArgumentNullException(nameof(pipelineInvoker));
            if (options == null) throw new ArgumentNullException(nameof(options));
            if (busGetter == null) throw new ArgumentNullException(nameof(busGetter));
            if (busLifetimeEvents == null) throw new ArgumentNullException(nameof(busLifetimeEvents));
            if (backoffStrategy == null) throw new ArgumentNullException(nameof(backoffStrategy));
            _transport = transport;
            _rebusLoggerFactory = rebusLoggerFactory;
            _pipeline = pipeline;
            _pipelineInvoker = pipelineInvoker;
            _options = options;
            _busGetter = busGetter;
            _backoffStrategy = backoffStrategy;
            _parallelOperationsManager = new ParallelOperationsManager(options.MaxParallelism);
            _log = _rebusLoggerFactory.GetCurrentClassLogger();

            if (_options.MaxParallelism < 1)
            {
                throw new ArgumentException($"Max parallelism is {_options.MaxParallelism} which is an invalid value");
            }

            if (options.WorkerShutdownTimeout < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException($"Cannot use '{options.WorkerShutdownTimeout}' as worker shutdown timeout as it");
            }

            busLifetimeEvents.WorkersStopped += WaitForContinuationsToFinish;
        }
Beispiel #2
0
 /// <summary>
 /// Constructs the bus.
 /// </summary>
 public RebusBus(IWorkerFactory workerFactory, IRouter router, ITransport transport, IPipelineInvoker pipelineInvoker, ISubscriptionStorage subscriptionStorage, Options options, IRebusLoggerFactory rebusLoggerFactory, BusLifetimeEvents busLifetimeEvents, IDataBus dataBus)
 {
     _workerFactory       = workerFactory;
     _router              = router;
     _transport           = transport;
     _pipelineInvoker     = pipelineInvoker;
     _subscriptionStorage = subscriptionStorage;
     _options             = options;
     _busLifetimeEvents   = busLifetimeEvents;
     _dataBus             = dataBus;
     _log = rebusLoggerFactory.GetLogger <RebusBus>();
 }
Beispiel #3
0
        protected override void DoRun()
        {
            var busLifetimeEvents = new BusLifetimeEvents();
            using (var transport = new AzureServiceBusTransport(GetConnectionString(ConnectionStringName), InputQueue, LoggerFactory, new TplAsyncTaskFactory(LoggerFactory), busLifetimeEvents))
            {
                var returnToSourceQueue = new ReturnToSourceQueue(transport)
                {
                    InputQueue = InputQueue,
                    DefaultOutputQueue = DefaultOutputQueue
                };

                returnToSourceQueue.Run();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Constructs the bus.
        /// </summary>
        public RebusBus(IWorkerFactory workerFactory, IRouter router, ITransport transport, IPipelineInvoker pipelineInvoker, ISubscriptionStorage subscriptionStorage, Options options, IRebusLoggerFactory rebusLoggerFactory, BusLifetimeEvents busLifetimeEvents, IDataBus dataBus)
        {
            _workerFactory       = workerFactory;
            _router              = router;
            _transport           = transport;
            _pipelineInvoker     = pipelineInvoker;
            _subscriptionStorage = subscriptionStorage;
            _options             = options;
            _busLifetimeEvents   = busLifetimeEvents;
            _dataBus             = dataBus;
            _log = rebusLoggerFactory.GetLogger <RebusBus>();

            var defaultBusName = $"Rebus {Interlocked.Increment(ref _busIdCounter)}";

            _busName = options.OptionalBusName ?? defaultBusName;
        }
Beispiel #5
0
        /// <summary>
        /// Constructs the bus.
        /// </summary>
        public RebusBus(IWorkersCoordinatorFactory workerFactory, IRouter router, ITransport transport, IPipelineInvoker pipelineInvoker, ISubscriptionStorage subscriptionStorage, Options options, IRebusLoggerFactory rebusLoggerFactory, BusLifetimeEvents busLifetimeEvents, ITopicNameConvention topicNameConvention)
        {
            _workerFactory       = workerFactory;
            _router              = router;
            _transport           = transport;
            _pipelineInvoker     = pipelineInvoker;
            _subscriptionStorage = subscriptionStorage;
            _options             = options;
            _busLifetimeEvents   = busLifetimeEvents;
            _log = rebusLoggerFactory.GetLogger <RebusBus>();
            _topicNameConvention = topicNameConvention;

            var defaultBusName = $"Rebus {Interlocked.Increment(ref _busIdCounter)}";

            _busName = options.OptionalBusName ?? defaultBusName;
            _workers = new Lazy <IWorkersCoordinator>(() => _workerFactory.CreateWorkersCoordinator("RebusBus WorkersCoordinator", 0), true);
        }
        /// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, BusLifetimeEvents busLifetimeEvents)
        {
            if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));

            _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            _connectionString = connectionString;
            _asyncTaskFactory = asyncTaskFactory;
            _log = rebusLoggerFactory.GetCurrentClassLogger();

            if (inputQueueAddress != null)
            {
                _inputQueueAddress = inputQueueAddress.ToLowerInvariant();
            }

            // if a timeout has been specified, we respect that - otherwise, we pick a sensible default:
            _receiveTimeout = _connectionString.Contains("OperationTimeout")
                ? default(TimeSpan?)
                : TimeSpan.FromSeconds(5);
        }
Beispiel #7
0
        protected override void SetUp()
        {
            var connectionString = StandardAzureServiceBusTransportFactory.ConnectionString;
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var asyncTaskFactory = new TplAsyncTaskFactory(consoleLoggerFactory);
            var busLifetimeEvents = new BusLifetimeEvents();
            new AzureServiceBusTransport(connectionString, QueueName, consoleLoggerFactory, asyncTaskFactory, busLifetimeEvents).PurgeInputQueue();

            _activator = new BuiltinHandlerActivator();

            _bus = Configure.With(_activator)
                .Transport(t => t.UseAzureServiceBus(connectionString, QueueName))
                .Options(o =>
                {
                    o.LogPipeline();
                })
                .Start();

            Using(_bus);
        }
        ITransport GetTransport()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var asyncTaskFactory = new TplAsyncTaskFactory(consoleLoggerFactory);
            var connectionString = StandardAzureServiceBusTransportFactory.ConnectionString;
            var busLifetimeEvents = new BusLifetimeEvents();

            if (_mode == AzureServiceBusMode.Basic)
            {
                var basicTransport = new BasicAzureServiceBusTransport(connectionString, _queueName, consoleLoggerFactory, asyncTaskFactory, busLifetimeEvents);
                Using(basicTransport);
                basicTransport.Initialize();
                basicTransport.PurgeInputQueue();
                return basicTransport;
            }
            var transport = new AzureServiceBusTransport(connectionString, _queueName, consoleLoggerFactory, asyncTaskFactory, busLifetimeEvents);
            Using(transport);
            transport.Initialize();
            transport.PurgeInputQueue();
            return transport;
        }