Example #1
0
        static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.SetServiceName(ServiceName);
                x.SetDescription("This service processes messages from queue provided by connection string. Each message received from queue sent using Messaging dll.");
                x.SetDisplayName("Spiral Message Queue Service");
                x.Service<QueueProcessor>(sc =>
                {
                    sc.ConstructUsing(() =>
                    {
                        var pConfig = new ProcessorConfiguration(1,
                            "DynamicDataResponseType",
                            "DynamicDataRequestType",
                            MessageProcessorDelegate,
                            1000,
                            "DynamicDataRequestQueue",
                            ConfigurationManager.ConnectionStrings["Connection"]);

                        return new QueueProcessor(pConfig);
                    });
                    sc.WhenStarted(s => s.Start());
                    sc.WhenStopped(s => s.Stop());
                    sc.BeforeStartingService(h => Trace.Listeners.Add(new ConsoleTraceListener()));
                });
                x.StartAutomatically();
                x.RunAsNetworkService();

            });
        }
        /// <summary>
        /// Returns the collection of filters associated with <paramref name="configuration"/>.
        /// </summary>
        /// <remarks>
        /// The implementation invokes <see cref="ProcessorConfiguration.Filters"/>.
        /// </remarks>
        /// <param name="configuration">The configuration.</param>
        /// <param name="descriptor">The handler descriptor. This value is not used.</param>
        /// <returns>A collection of filters.</returns>
        public IEnumerable<FilterInfo> GetFilters(ProcessorConfiguration configuration, HandlerDescriptor descriptor)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            return configuration.Filters;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandHandlerSettings"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public CommandHandlerSettings(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.configuration = configuration;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultInterceptionProvider"/> class.
        /// </summary>
        public DefaultInterceptionProvider(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.configuration = configuration;
        }
Example #5
0
        public void WhenGettingOrThrowUnknowServiceThenThrowsInvalidOperationException()
        {
            ProcessorConfiguration config = new ProcessorConfiguration();
            DefaultServices services = new DefaultServices(config);
            services.Replace(typeof(ICommandHandlerActivator), null);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => services.GetServiceOrThrow<ICommandHandlerActivator>());
        }
Example #6
0
        public EventHandlerTypeCache(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.configuration = configuration;
            this.cache = new Lazy<Dictionary<Type, ILookup<Type, Type>>>(this.InitializeCache);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCommandHandlerSelector"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public DefaultCommandHandlerSelector(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.handlerInfoCache = new Lazy<ConcurrentDictionary<Type, CommandHandlerDescriptor>>(this.InitializeHandlerInfoCache);
            this.configuration = configuration;
            this.commandHandlerTypeCache = new CommandHandlerTypeCache(this.configuration);
        }
Example #8
0
        /// <summary>
        /// Gets an exception handler that calls the registered handler service, if any, and ensures exceptions do not
        /// accidentally propagate to the host.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>
        /// An exception handler that calls any registered handler and ensures exceptions do not accidentally propagate
        /// to the host.
        /// </returns>
        public static IExceptionHandler GetHandler(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            ServicesContainer services = configuration.Services;
            Contract.Assert(services != null);
            return GetHandler(services);
        }
Example #9
0
        /// <summary>Gets an exception logger that calls all registered logger services.</summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>A composite logger.</returns>
        public static IExceptionLogger GetLogger(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            ServicesContainer services = configuration.Services;
            Contract.Assert(services != null);
            return GetLogger(services);
        }
Example #10
0
        public static CommandQueueRunner Create(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            var processor = configuration.Services.GetServiceOrThrow<IMessageProcessor>();
            var receiver = configuration.Services.GetServiceOrThrow<ICommandReceiver>();

            return new CommandQueueRunner(processor, receiver);
        }
        public void EnableAzureMessageQueuing()
        {
            // Arrange 
            ProcessorConfiguration config = new ProcessorConfiguration();

            // Assert
            config.EnableAzureMessageQueuing("Endpoint=sb://test.servicebus.windows.net;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SECRET");

            // Assert
            Assert.IsType<AzureCommandQueue>(config.Services.GetService<ICommandReceiver>());
            Assert.IsType<AzureCommandQueue>(config.Services.GetService<ICommandSender>());
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerRequest"/> class. 
 /// The request will be a child request of the <paramref name="parentRequest"/>.
 /// </summary> 
 /// <param name="configuration">The configuration.</param>
 /// <param name="command">The command.</param>
 /// <param name="parentRequest">The parent request. </param>
 public CommandHandlerRequest(ProcessorConfiguration configuration, ICommand command, HandlerRequest parentRequest)
     : base(configuration, parentRequest)
 {
     if (command == null)
     {
         throw Error.ArgumentNull("command");
     }
     
     this.Command = command;
     this.MessageType = command.GetType();
     this.ModelState = new ModelStateDictionary();
 }
Example #13
0
        /// <summary>
        /// Returns the collection of filters associated with <paramref name="descriptor"/>.
        /// </summary>
        /// <remarks>
        /// The implementation invokes <see cref="HandlerDescriptor.GetFilters()"/>.
        /// </remarks>
        /// <param name="configuration">The configuration. This value is not used.</param>
        /// <param name="descriptor">The handler descriptor.</param>
        /// <returns>A collection of filters.</returns>
        public IEnumerable<FilterInfo> GetFilters(ProcessorConfiguration configuration, HandlerDescriptor descriptor)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            if (descriptor == null)
            {
                throw Error.ArgumentNull("descriptor");
            }

            IEnumerable<FilterInfo> filters = descriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Handler));

            return filters;
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandlerRequest"/> class. 
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="event">The event.</param>
        /// <param name="parentRequest">The parent request. </param>
        public EventHandlerRequest(ProcessorConfiguration configuration, IEvent @event, HandlerRequest parentRequest)
            : base(configuration, parentRequest)
        {
            if (@event == null)
            {
                throw Error.ArgumentNull("event");
            }

            // Events cannot be called without a parent request
            if (parentRequest == null)
            {
                throw Error.ArgumentNull("parentRequest");
            }

            this.Event = @event;
            this.MessageType = @event.GetType();
        }
Example #15
0
        public async Task PlaceOrder_WithMessageQueuing_EventsArePublished()
        {
            IUnityContainer container = new UnityContainer();

            Mock<ISpy> spy = new Mock<ISpy>();
            container.RegisterInstance(typeof(ISpy), spy.Object);

            using (ProcessorConfiguration config = new ProcessorConfiguration())
            {
                config.EnableInMemoryMessageQueuing();
                config.RegisterContainer(container);
                using (MessageProcessor processor = new MessageProcessor(config))
                {
                    PlaceOrder command = new PlaceOrder(1);
                    await processor.ProcessAsync(command);

                    CancellationTokenSource cts = new CancellationTokenSource(5);
                    await config.CommandBroker.StartAsync(cts.Token);

                    // commands assertions
                    spy.Verify(s => s.Spy("PlaceOrder"), Times.Once());
                    spy.Verify(s => s.Spy("MakePayment"), Times.Once());
                    spy.Verify(s => s.Spy("MakeReservation"), Times.Once());
                    spy.Verify(s => s.Spy("AddSeatsToWaitList"), Times.Never());

                    // events assertions
                    spy.Verify(s => s.Spy("OrderConfirmed"), Times.Exactly(2));
                    spy.Verify(s => s.Spy("OrderCreated"), Times.Once());
                    spy.Verify(s => s.Spy("PaymentAccepted"), Times.Once());
                    spy.Verify(s => s.Spy("SeatsReserved"), Times.Once());
                    spy.Verify(s => s.Spy("SeatsNotReserved"), Times.Never());

                    // ctor assertions
                    spy.Verify(s => s.Spy("OrderProcessManager ctor"), Times.Exactly(3));
                    spy.Verify(s => s.Spy("Order ctor"), Times.Exactly(2));
                    spy.Verify(s => s.Spy("Payment ctor"), Times.Once());
                    spy.Verify(s => s.Spy("Payment ctor"), Times.Once());
                    spy.Verify(s => s.Spy("Payment ctor"), Times.Once());
                    spy.Verify(s => s.Spy("Reservation ctor"), Times.Exactly(2));
                }
            }
        }
 public TransactionFilterAttributeTests()
 {
     this.config = new ProcessorConfiguration();
 }
Example #17
0
 public TransactionFilterAttributeTests()
 {
     this.config = new ProcessorConfiguration();
 }
 public TestProcessResultFlowFileController(ProcessorConfiguration <EntityB, EntityC> config)
     : base(config)
 {
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerRequest"/> class. 
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="command">The command.</param>
 public CommandHandlerRequest(ProcessorConfiguration configuration, ICommand command)
     : this(configuration, command, null)
 {
 }
Example #20
0
 public CacheAttributeFixture()
 {
     this.cache  = new Mock <ObjectCache>();
     this.config = new ProcessorConfiguration();
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerRequest"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="command">The command.</param>
 public CommandHandlerRequest(ProcessorConfiguration configuration, ICommand command)
     : this(configuration, command, null)
 {
 }
 public TestCsvFlowController(ProcessorConfiguration <EnitityA, EntityB> config)
     : base(config)
 {
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultEventWorker"/> class.
 /// </summary>
 /// <param name="configuration"></param>
 public DefaultEventWorker(ProcessorConfiguration configuration)
 {
     this.Configuration = configuration;
 }
Example #24
0
 public CsvFlowFileController(
     ProcessorConfiguration <TIn, TOut> config,
     Func <IFlowFileController, Processor <TIn, TOut> > getProcessor = null)
     : base(config, new CsvProcessorReader <TIn>(), getProcessor)
 {
 }
Example #25
0
 public NotNullAttributeProcessor([NotNull] ProcessorConfiguration configuration, [NotNull] ILogger logger)
     : base(configuration, logger)
 {
 }
Example #26
0
 public CacheAttributeFixture()
 {
     this.cache = new Mock<ObjectCache>();
     this.config = new ProcessorConfiguration();
 }
Example #27
0
 public static void Register(ProcessorConfiguration config)
 {
     config.RegisterContextFactory(() => new ConferenceDbContext(DbConnectionFactory.CreatePersistent("1")));
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultCommandWorker"/> class.
 /// </summary>
 /// <param name="configuration"></param>
 public DefaultCommandWorker(ProcessorConfiguration configuration)
 {
     this.Configuration = configuration;
 }
Example #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultEventWorker"/> class.
 /// </summary>
 /// <param name="configuration"></param>
 public DefaultEventWorker(ProcessorConfiguration configuration)
 {
     this.Configuration = configuration;
 }