Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Reads the host machine which runs the RabbitMQ.
            var rabbitHost = this.Configuration["rabbit:host"];

            // Reads the RabbitMQ exchange setting.
            var rabbitExchangeName = this.Configuration["rabbit:exchange"];

            // Reads the name of the event queue.
            var rabbitEventQueueName = this.Configuration["rabbit:eventQueue"];

            // Reads the name of the command queue.
            var rabbitCommandQueueName = this.Configuration["rabbit:commandQueue"];

            var connectionFactory = new ConnectionFactory {
                HostName = rabbitHost
            };
            var messageSerializer = new MessageJsonSerializer();

            // Add framework services.
            services.AddMvc();

            services.AddApworks()
            .WithCommandSender(new CommandBus(connectionFactory, messageSerializer, rabbitExchangeName, ExchangeType.Topic))
            .WithCommandSubscriber(new CommandBus(connectionFactory, messageSerializer, rabbitExchangeName, ExchangeType.Topic, rabbitCommandQueueName))
            .WithDefaultCommandConsumer("commands.*")
            .AddCommandHandler(new PostTextCommandHandler())
            .WithEventSubscriber(new EventBus(connectionFactory, messageSerializer, rabbitExchangeName, ExchangeType.Topic, rabbitEventQueueName))
            .WithDefaultEventConsumer("events.*")
            .AddEventHandler(new AccountCreatedEventHandler(this.Configuration))
            .Configure();

            var serviceProvider = services.BuildServiceProvider();

            this.commandSender = serviceProvider.GetService <ICommandSender>();

            this.eventConsumer = serviceProvider.GetService <IEventConsumer>();
            this.eventConsumer.Consume();

            this.commandConsumer = serviceProvider.GetService <ICommandConsumer>();
            this.commandConsumer.Consume();
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Microservice"/> class.
 /// </summary>
 /// <param name="commandConsumer">The command consumer.</param>
 /// <param name="eventConsumer">The event consumer.</param>
 public Microservice(ICommandConsumer commandConsumer, IEventConsumer eventConsumer)
 {
     this.commandConsumer = commandConsumer;
     this.eventConsumer   = eventConsumer;
 }
Пример #3
0
 public AccountService(ICommandConsumer commandConsumer, IEventConsumer eventConsumer)
     : base(commandConsumer, eventConsumer)
 {
 }
Пример #4
0
 public WhenSendingSwitchCommand(ITestOutputHelper testOutputHelper)
 {
     _commandConsumer = A.Fake <ICommandConsumer>();
     _testDevice      = new SwitchableLight(DeviceId, new TestLogger(testOutputHelper), new TestDataProvider(), new DataSourceFactory(), _commandConsumer, new CommandSinkFactory());
 }
Пример #5
0
        protected void AddCommandSink(string commandId, ICommandConsumer commandConsumer)
        {
            var commandSink = _commandSinkFactory.Create(GetCommandSinkId(Id, commandId), _logger, commandConsumer);

            _commandSinks.Add(commandSink);
        }
Пример #6
0
 public CommandSink(string id, ILog logger, ICommandConsumer commandConsumer)
 {
     Id               = id;
     _logger          = logger;
     _commandConsumer = commandConsumer;
 }
Пример #7
0
 public SwitchableLight(string id, ILog logger, IDataProvider dataProvider, IDataSourceFactory dataSourceFactory, ICommandConsumer commandConsumer, ICommandSinkFactory commandSinkFactory)
     : base(id, logger, dataSourceFactory, commandSinkFactory)
 {
     AddDataSource(StateDataId, dataProvider);
     AddCommandSink(SwitchCommandId, commandConsumer);
 }
Пример #8
0
 public CommandConsumerAdapter(ICommandConsumer <TCommand> commandConsumer)
 {
     Guard.NotNull(commandConsumer, nameof(commandConsumer));
     this.commandConsumer = commandConsumer;
 }
 public InMemoryCommandProducer(ICommandConsumer consumer)
 {
     this.consumer = consumer;
 }
Пример #10
0
 public SocialService(ICommandConsumer commandConsumer, IEventConsumer eventConsumer)
     : base(commandConsumer, eventConsumer)
 {
 }
Пример #11
0
 public ICommandSink Create(string id, ILog logger, ICommandConsumer commandConsumer)
 {
     return(new CommandSink(id, logger, commandConsumer));
 }
Пример #12
0
 public TextingService(ICommandConsumer commandConsumer, IEventConsumer eventConsumer)
     : base(commandConsumer, eventConsumer)
 {
 }