Common settings for scale-out message bus implementations.
        public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                                     Action <int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     TraceSource trace,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutConfiguration configuration)
        {
            if (configuration.QueueBehavior != QueuingBehavior.Disabled && configuration.MaxQueueLength == 0)
            {
                throw new InvalidOperationException(Resources.Error_ScaleoutQueuingConfig);
            }

            _streams = new ScaleoutStream[streamCount];
            _send    = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue     = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue      = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i]       = new ScaleoutStream(trace, "Stream(" + i + ")", configuration.QueueBehavior, configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection <ScaleoutMappingStore>(receiveMapping);
        }
Esempio n. 2
0
 public void Configuration(IAppBuilder app)
 {
     var config = new ScaleoutConfiguration { MaxQueueLength = 10, QueueBehavior = QueuingBehavior.Always };
     var omb = new OrleansMessageBus(GlobalHost.DependencyResolver, config);
     GlobalHost.DependencyResolver.Register(typeof(IMessageBus), () => omb);
     app.MapSignalR();
 }
        public ScaleoutStreamManager(Func<int, IList<Message>, Task> send,
                                     Action<int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     TraceSource trace,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutConfiguration configuration)
        {
            if (configuration.QueueBehavior != QueuingBehavior.Disabled && configuration.MaxQueueLength == 0)
            {
                throw new InvalidOperationException(Resources.Error_ScaleoutQueuingConfig);
            }

            _streams = new ScaleoutStream[streamCount];
            _send = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i] = new ScaleoutStream(trace, "Stream(" + i + ")", configuration.QueueBehavior, configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection<ScaleoutMappingStore>(receiveMapping);
        }
        public void ValidMaxQueueLength(int maxLength)
        {
            var config = new ScaleoutConfiguration();
            config.MaxQueueLength = maxLength;

            Assert.Equal(maxLength, config.MaxQueueLength);
        }
Esempio n. 5
0
        public ScaleoutStreamManager(Func<int, IList<Message>, Task> send,
                                     Action<int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     TraceSource trace,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutConfiguration configuration)
        {
            _streams = new ScaleoutStream[streamCount];
            _send = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i] = new ScaleoutStream(trace, "Stream(" + i + ")", configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection<ScaleoutMappingStore>(receiveMapping);
        }
 /// <summary>
 /// Use NServiceBus backplane for SignalR.
 /// </summary>
 /// <param name="resolver">The dependency resolver.</param>
 /// <param name="busInstance">The instance of the NServiceBus IBus instance inside the current host.</param>
 /// <param name="configuration">Scaleout configuration parameters to be used by SignalR.</param>
 /// <returns>The dependency resolver.</returns>
 public static IDependencyResolver UseNServiceBus(this IDependencyResolver resolver, IBus busInstance, ScaleoutConfiguration configuration)
 {
     var bus = new Lazy<NServiceBusMessageBus>(() => new NServiceBusMessageBus(resolver, busInstance, configuration));
     resolver.Register(typeof(IMessageBus), () => bus.Value);
     resolver.Register(typeof(NServiceBusMessageBus), () => bus.Value);
     return resolver;
 }
Esempio n. 7
0
        public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                                     Action <int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     TraceSource trace,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutConfiguration configuration)
        {
            _streams = new ScaleoutStream[streamCount];
            _send    = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue     = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue      = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i]       = new ScaleoutStream(trace, "Stream(" + i + ")", configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection <ScaleoutMappingStore>(receiveMapping);
        }
        public NServiceBusMessageBus(IDependencyResolver resolver, IBus busInstance, ScaleoutConfiguration configuration)
            : base(resolver, configuration)
        {
            _bus = busInstance;

            // By default, there is only 1 stream in this NServiceBus backplane, and we'll open it here
            Open(0);
        }
Esempio n. 9
0
 public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                              Action <int, ulong, ScaleoutMessage> receive,
                              int streamCount,
                              TraceSource trace,
                              IPerformanceCounterManager performanceCounters,
                              ScaleoutConfiguration configuration)
     : this(send, receive, streamCount, trace, performanceCounters, configuration,
            DefaultConfigurationManager.DefaultMaxScaleoutMappingsPerStream)
 {
 }
        public NServiceBusMessageBus(IDependencyResolver resolver, IBus busInstance, ScaleoutConfiguration configuration)
            : base(resolver, configuration)
        {
            Bus = busInstance;
            Configure.Instance.Configurer.ConfigureComponent<Receiver>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty((r) => r.SignalRMessageBus, this);

            // By default, there is only 1 stream in this NServiceBus backplane, and we'll open it here
            Open(0);
        }
        public void StreamManagerValidatesScaleoutConfig()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var config = new ScaleoutConfiguration();

            config.QueueBehavior = QueuingBehavior.Always;
            config.MaxQueueLength = 0;

            Assert.Throws<InvalidOperationException>(() => new ScaleoutStreamManager((int x, IList<Message> list) => { return TaskAsyncHelper.Empty; },
                (int x, ulong y, ScaleoutMessage msg) => { }, 0, new TraceSource("Stream Manager"), perfCounters, config));
        }
        protected ScaleoutMessageBus(IDependencyResolver resolver, ScaleoutConfiguration configuration)
            : base(resolver)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            var traceManager = resolver.Resolve<ITraceManager>();
            _trace = traceManager["SignalR." + typeof(ScaleoutMessageBus).Name];
            _streamManager = new Lazy<ScaleoutStreamManager>(() => new ScaleoutStreamManager(Send, OnReceivedCore, StreamCount, configuration, _trace));
        }
Esempio n. 13
0
        protected ScaleoutMessageBus(IDependencyResolver resolver, ScaleoutConfiguration configuration)
            : base(resolver)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            var traceManager = resolver.Resolve <ITraceManager>();

            _trace         = traceManager["SignalR." + typeof(ScaleoutMessageBus).Name];
            _streamManager = new Lazy <ScaleoutStreamManager>(() => new ScaleoutStreamManager(Send, OnReceivedCore, StreamCount, configuration, _trace));
        }
        public void EnqueueWithoutOpenRaisesOnError()
        {
            var tcs = new TaskCompletionSource<object>();
            var config = new ScaleoutConfiguration()
            {
                RetryOnError = true,
                OnError = ex => tcs.SetException(ex)
            };

            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", config);

            queue.Enqueue(_ => { throw new InvalidOperationException(); }, null);

            Assert.Throws<AggregateException>(() => tcs.Task.Wait());
        }
Esempio n. 15
0
        public OrleansMessageBus(IDependencyResolver resolver, ScaleoutConfiguration configuration)
            : base(resolver, configuration)
        {
            grain = PubSubGrainFactory.GetGrain(Guid.NewGuid());

            subscriber = new MessageObserver((messages) =>
            {
                lock (grain)
                {
                    OnReceived(messages[0].StreamIndex, messages.Select(x => x.MappingId).Max(), new ScaleoutMessage(messages));
                }
            });
            subscriberReference = MessageObserverFactory.CreateObjectReference(subscriber).Result;
            grain.Subscribe(subscriberReference).Wait();
        }
Esempio n. 16
0
        protected ScaleoutMessageBus(IDependencyResolver resolver, ScaleoutConfiguration configuration)
            : base(resolver)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _traceManager = resolver.Resolve <ITraceManager>();
            _trace        = _traceManager["SignalR." + typeof(ScaleoutMessageBus).Name];
            _perfCounters = resolver.Resolve <IPerformanceCounterManager>();
            var maxScaloutMappings = resolver.Resolve <IConfigurationManager>().MaxScaleoutMappingsPerStream;

            _streamManager = new Lazy <ScaleoutStreamManager>(
                () => new ScaleoutStreamManager(Send, OnReceivedCore, StreamCount, _trace, _perfCounters, configuration, maxScaloutMappings));
        }
Esempio n. 17
0
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            app.MapSignalR();

            Bus = Configure
                .With()
                .DefaultBuilder()
                .UseTransport<Msmq>()
                .UnicastBus()
                .LoadMessageHandlers()
                .CreateBus()
                .Start();

            var config = new ScaleoutConfiguration() { MaxQueueLength = 100 }; // Or whatever you want
            GlobalHost.DependencyResolver.UseNServiceBus(Bus, config);
        }
        public ScaleoutTaskQueue(TraceSource trace, string tracePrefix, ScaleoutConfiguration configuration, int size)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _trace = trace;
            _tracePrefix = tracePrefix;
            _configuration = configuration;
            _size = size;

            InitializeCore();
        }
        public FileSystemMessageBus(IDependencyResolver resolver, ScaleoutConfiguration configuration)
            : base(resolver, configuration) {
            Open(0); // Use only one stream

            if (Directory.Exists(BasePath)) {
                var files = new DirectoryInfo(BasePath).GetFiles();
                foreach (var file in files) {
                    file.Delete();
                }
            } else {
                Directory.CreateDirectory(BasePath);
            }

            _watcher = new FileSystemWatcher(BasePath, "*.txt") {
                IncludeSubdirectories = false,
                EnableRaisingEvents = true
            };
            _watcher.Created += FileCreated;
        }
Esempio n. 20
0
        public ScaleoutTaskQueue(TraceSource trace, string tracePrefix, ScaleoutConfiguration configuration, int size)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _trace         = trace;
            _tracePrefix   = tracePrefix;
            _configuration = configuration;
            _size          = size;

            InitializeCore();
        }
        public ScaleoutStreamManager(Func<int, IList<Message>, Task> send,
                                     Action<int, ulong, IList<Message>> receive,
                                     int streamCount,
                                     ScaleoutConfiguration configuration,
                                     TraceSource trace)
        {
            _sendQueues = new ScaleoutTaskQueue[streamCount];
            _send = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            for (int i = 0; i < streamCount; i++)
            {
                _sendQueues[i] = new ScaleoutTaskQueue(trace, "Stream(" + i + ")", configuration);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection<ScaleoutMappingStore>(receiveMapping);
        }
Esempio n. 22
0
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            app.MapSignalR();

            // Note: to get this working, make sure that the user account your app pool runs under has sufficient access to all queues
            // involved in this setup! That means: all signalr.nservicebus.backplaneservice* queues and the System.Web* queues.
            Bus = Configure
                .With()
                .DefaultBuilder()
                .UseTransport<Msmq>()
                .UseInMemoryTimeoutPersister()
                .UnicastBus()
                .LoadMessageHandlers()
                .CreateBus()
                .Start();

            var config = new ScaleoutConfiguration() { MaxQueueLength = 100 }; // Or whatever you want
            GlobalHost.DependencyResolver.UseNServiceBus(Bus, config);
        }
Esempio n. 23
0
        public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                                     Action <int, ulong, IList <Message> > receive,
                                     int streamCount,
                                     ScaleoutConfiguration configuration,
                                     TraceSource trace)
        {
            _sendQueues = new ScaleoutTaskQueue[streamCount];
            _send       = send;
            _receive    = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            for (int i = 0; i < streamCount; i++)
            {
                _sendQueues[i]    = new ScaleoutTaskQueue(trace, "Stream(" + i + ")", configuration);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection <ScaleoutMappingStore>(receiveMapping);
        }
 public void InvalidMaxQueueLength(int maxLength)
 {
     var config = new ScaleoutConfiguration();
     Assert.Throws<ArgumentOutOfRangeException>(() => config.MaxQueueLength = maxLength);
 }
 public ScaleoutTaskQueue(TraceSource trace, string tracePrefix, ScaleoutConfiguration configuration)
     : this(trace, tracePrefix, configuration, DefaultQueueSize)
 {
 }
Esempio n. 26
0
 protected void UseMessageBus(MessageBusType type, IDependencyResolver resolver, ScaleoutConfiguration configuration = null, int streams = 1)
 {
     switch (type)
     {
         case MessageBusType.Default:
             break;
         case MessageBusType.Fake:
             var bus = new FakeScaleoutBus(resolver, streams);
             resolver.Register(typeof(IMessageBus), () => bus);
             break;
         case MessageBusType.SqlServer:
             break;
         case MessageBusType.ServiceBus:
             break;
         case MessageBusType.Redis:
             break;
         default:
             break;
     }
 }
        public void ThrowingFromErrorCallbackIsCaught()
        {
            var config = new ScaleoutConfiguration()
            {
                RetryOnError = true,
                OnError = ex =>
                {
                    throw new Exception();
                }
            };

            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", config);
            queue.SetError(new Exception());
        }
Esempio n. 28
0
 public ScaleoutTaskQueue(TraceSource trace, string tracePrefix, ScaleoutConfiguration configuration)
     : this(trace, tracePrefix, configuration, DefaultQueueSize)
 {
 }