コード例 #1
0
        public static ENodeConfiguration StartRabbitMQ(this ENodeConfiguration enodeConfiguration)
        {
            var amqpUri    = new Uri("amqp://*****:*****@localhost/test");
            var clientName = "BankTransferSample";

            _commandService.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                               new string[] { Constants.CommandTopic },
                                               new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)));
            _applicationMessagePublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                            new string[] { Constants.ApplicationMessageTopic });
            _domainEventPublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                     new string[] { Constants.EventTopic });
            _exceptionPublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                   new string[] { Constants.ExceptionTopic });

            _commandConsumer = new CommandConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.CommandTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.ApplicationMessageTopic);
            _eventConsumer = new DomainEventConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.EventTopic);
            _exceptionConsumer = new DomainExceptionConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.ExceptionTopic);

            _exceptionConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _commandConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainEventPublisher.Start();
            _exceptionPublisher.Start();
            _commandService.Start();

            return(enodeConfiguration);
        }