예제 #1
0
        private CqrsEngine CreateEngine(IComponentContext ctx, IMessagingEngine messagingEngine)
        {
            var rabbitMqConventionEndpointResolver =
                new RabbitMqConventionEndpointResolver("RabbitMq", SerializationFormat.MessagePack,
                                                       environment: _settings.EnvironmentName);

            var registrations = new List <IRegistration>
            {
                Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                RegisterDefaultRouting(),
                RegisterSpecialLiquidationSaga(),
                RegisterLiquidationSaga(),
                RegisterContext(),
                Register.CommandInterceptors(new DefaultCommandLoggingInterceptor(_log)),
                Register.EventInterceptors(new DefaultEventLoggingInterceptor(_log))
            };

            var fakeGavel = RegisterGavelContextIfNeeded();

            if (fakeGavel != null)
            {
                registrations.Add(fakeGavel);
            }

            var correlationManager = ctx.Resolve <CqrsCorrelationManager>();
            var engine             = new CqrsEngine(_log, ctx.Resolve <IDependencyResolver>(), messagingEngine,
                                                    new DefaultEndpointProvider(), true, registrations.ToArray());

            engine.SetReadHeadersAction(correlationManager.FetchCorrelationIfExists);
            engine.SetWriteHeadersFunc(correlationManager.BuildCorrelationHeadersIfExists);
            engine.StartPublishers();

            return(engine);
        }
        private CqrsEngine CreateEngine(IComponentContext ctx, IMessagingEngine messagingEngine)
        {
            var rabbitMqConventionEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.MessagePack,
                environment: _settings.EnvironmentName);

            var engine = new CqrsEngine(
                _log,
                ctx.Resolve <IDependencyResolver>(),
                messagingEngine,
                new DefaultEndpointProvider(),
                true,
                Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                RegisterDefaultRouting(),
                RegisterWithdrawalSaga(),
                RegisterDepositSaga(),
                RegisterClosePositionSaga(),
                RegisterNegativeProtectionSaga(),
                RegisterGiveTemporaryCapitalSaga(),
                RegisterRevokeTemporaryCapitalSaga(),
                RegisterDeleteAccountsSaga(),
                RegisterContext(),
                Register.CommandInterceptors(new DefaultCommandLoggingInterceptor(_log)),
                Register.EventInterceptors(new DefaultEventLoggingInterceptor(_log)));
            var correlationManager = ctx.Resolve <CqrsCorrelationManager>();

            engine.SetReadHeadersAction(correlationManager.FetchCorrelationIfExists);
            engine.SetWriteHeadersFunc(correlationManager.BuildCorrelationHeadersIfExists);
            engine.StartAll();

            return(engine);
        }
예제 #3
0
파일: CqrsModule.cs 프로젝트: alpo-8/MT
        private CqrsEngine CreateEngine(IComponentContext ctx, IMessagingEngine messagingEngine)
        {
            var rabbitMqConventionEndpointResolver =
                new RabbitMqConventionEndpointResolver("RabbitMq", "messagepack",
                                                       environment: _settings.EnvironmentName);

            var registrations = new List <IRegistration>
            {
                Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                RegisterDefaultRouting(),
                RegisterSpecialLiquidationSaga(),
                RegisterLiquidationSaga(),
                RegisterContext(),
            };

            var fakeGavel = RegisterGavelContextIfNeeded();

            if (fakeGavel != null)
            {
                registrations.Add(fakeGavel);
            }

            return(new CqrsEngine(_log, ctx.Resolve <IDependencyResolver>(), messagingEngine,
                                  new DefaultEndpointProvider(), true, registrations.ToArray()));
        }
        public CqrsEngine CreateEngine()
        {
            var rabbitMqConventionEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.MessagePack,
                environment: _settings.EnvironmentName);
            var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory
            {
                Uri = new Uri(_settings.ConnectionString, UriKind.Absolute)
            };

            return(new CqrsEngine(
                       _log,
                       new AutofacDependencyResolver(Mock.Of <IComponentContext>()),
                       new MessagingEngine(_log,
                                           new TransportResolver(new Dictionary <string, TransportInfo>
            {
                {
                    "RabbitMq",
                    new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName,
                                      rabbitMqSettings.Password, "None", "RabbitMq")
                }
            }),
                                           new RabbitMqTransportFactory()),
                       new DefaultEndpointProvider(),
                       false,
                       Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                       RegisterContext()));
        }
예제 #5
0
        protected override void Load(ContainerBuilder builder)
        {
            var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory {
                Uri = _appSettings.CurrentValue.SagasRabbitMq.RabbitConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>().SingleInstance();
            MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;

            builder.RegisterType <AssetsProjection>();

            builder.Register(ctx => new MessagingEngine(ctx.Resolve <ILogFactory>(),
                                                        new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "RabbitMq", new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName, rabbitMqSettings.Password, "None", "RabbitMq") }
            }),
                                                        new RabbitMqTransportFactory(ctx.Resolve <ILogFactory>()))).As <IMessagingEngine>().SingleInstance();

            builder.Register(ctx =>
            {
                var msgPackResolver = new RabbitMqConventionEndpointResolver(
                    "RabbitMq",
                    SerializationFormat.MessagePack,
                    environment: "lykke",
                    exclusiveQueuePostfix: "k8s");

                var engine = new CqrsEngine(
                    ctx.Resolve <ILogFactory>(),
                    ctx.Resolve <IDependencyResolver>(),
                    ctx.Resolve <IMessagingEngine>(),
                    new DefaultEndpointProvider(),
                    true,

                    Register.EventInterceptors(new DefaultEventLoggingInterceptor(ctx.Resolve <ILogFactory>())),

                    Register.DefaultEndpointResolver(msgPackResolver),

                    Register.BoundedContext(LimitationsBoundedContext.Name)
                    .ListeningEvents(typeof(AssetCreatedEvent), typeof(AssetUpdatedEvent))
                    .From(Assets.BoundedContext.Name).On("events")
                    .WithProjection(typeof(AssetsProjection), Assets.BoundedContext.Name)

                    .PublishingEvents(
                        typeof(ClientDepositEvent),
                        typeof(ClientWithdrawEvent)
                        ).With("events")
                    .WithEndpointResolver(msgPackResolver)
                    );

                engine.StartPublishers();
                return(engine);
            })
            .As <ICqrsEngine>()
            .AutoActivate()
            .SingleInstance();
        }
예제 #6
0
        protected override void Load(ContainerBuilder builder)
        {
            Messaging.Serialization.MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
            var rabbitMqSagasSettings = new RabbitMQ.Client.ConnectionFactory {
                Uri = _settings.CurrentValue.SwiftWithdrawalService.Cqrs.RabbitConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>();

            var messagingEngine = new MessagingEngine(_log,
                                                      new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "SagasRabbitMq", new TransportInfo(rabbitMqSagasSettings.Endpoint.ToString(), rabbitMqSagasSettings.UserName, rabbitMqSagasSettings.Password, "None", "RabbitMq") }
            }),
                                                      new RabbitMqTransportFactory());

            var sagasEndpointResolver = new RabbitMqConventionEndpointResolver(
                "SagasRabbitMq",
                "messagepack",
                environment: "lykke",
                exclusiveQueuePostfix: "k8s");

            builder.RegisterType <SwiftCashoutRequestCommandHandler>().SingleInstance();
            builder.RegisterType <SwiftRequestLogProjection>().SingleInstance();



            builder.Register(ctx =>
            {
                string commandsRoute = "commands";
                string eventsRoute   = "events";

                return(new CqrsEngine(_log,
                                      ctx.Resolve <IDependencyResolver>(),
                                      messagingEngine,
                                      new DefaultEndpointProvider(),
                                      true,
                                      Register.DefaultEndpointResolver(sagasEndpointResolver),

                                      Register.BoundedContext(SwiftWithdrawalBoundedContext.Name)
                                      .ListeningCommands(typeof(SwiftCashoutCreateCommand))
                                      .On(commandsRoute)
                                      .WithCommandsHandler <SwiftCashoutRequestCommandHandler>()
                                      .PublishingEvents(typeof(SwiftCashoutCreatedEvent))
                                      .With(eventsRoute)

                                      .ListeningEvents(typeof(SwiftCashoutCreatedEvent))
                                      .From(SwiftWithdrawalBoundedContext.Name)
                                      .On(eventsRoute)
                                      .WithProjection(typeof(SwiftRequestLogProjection), SwiftWithdrawalBoundedContext.Name)));
            })
            .As <ICqrsEngine>()
            .SingleInstance()
            .AutoActivate();
        }
예제 #7
0
        protected override void Load(ContainerBuilder builder)
        {
            string eventsRoute = "events";

            MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
            var rabbitMqSagasSettings = new RabbitMQ.Client.ConnectionFactory {
                Uri = _settings.CurrentValue.SagasRabbitMq.RabbitConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>();

            builder.RegisterType <RegistrationSaga>().SingleInstance();

            builder.Register(ctx =>
            {
                var logFactory = ctx.Resolve <ILogFactory>();

                var messagingEngine = new MessagingEngine(logFactory,
                                                          new TransportResolver(new Dictionary <string, TransportInfo>
                {
                    {
                        "SagasRabbitMq",
                        new TransportInfo(rabbitMqSagasSettings.Endpoint.ToString(),
                                          rabbitMqSagasSettings.UserName, rabbitMqSagasSettings.Password, "None", "RabbitMq")
                    }
                }),
                                                          new RabbitMqTransportFactory(logFactory));

                var sagasEndpointResolver = new RabbitMqConventionEndpointResolver(
                    "SagasRabbitMq",
                    SerializationFormat.MessagePack,
                    environment: "lykke",
                    exclusiveQueuePostfix: "k8s");

                return(new CqrsEngine(logFactory,
                                      new AutofacDependencyResolver(ctx.Resolve <IComponentContext>()),
                                      messagingEngine,
                                      new DefaultEndpointProvider(),
                                      true,
                                      false, //don't log input messages
                                      Register.DefaultEndpointResolver(sagasEndpointResolver),

                                      Register.Saga <RegistrationSaga>("regulation-registration-saga")
                                      .ListeningEvents(typeof(ClientRegisteredEvent))
                                      .From(RegistrationBoundedContext.Name).On(eventsRoute)
                                      .WithEndpointResolver(sagasEndpointResolver)
                                      .ProcessingOptions(eventsRoute).MultiThreaded(2).QueueCapacity(256)
                                      ));
            })
            .As <ICqrsEngine>()
            .AutoActivate()
            .SingleInstance();
        }
        private CqrsEngine CreateEngine(IComponentContext ctx, IMessagingEngine messagingEngine)
        {
            var rabbitMqConventionEndpointResolver =
                new RabbitMqConventionEndpointResolver("RabbitMq", SerializationFormat.MessagePack,
                                                       environment: _settings.EnvironmentName);

            var registrations = new List <IRegistration>
            {
                Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                Register.CommandInterceptors(new DefaultCommandLoggingInterceptor(_log)),
                Register.EventInterceptors(new DefaultEventLoggingInterceptor(_log)),
                RegisterContext(),
            };

            return(new CqrsEngine(_log, ctx.Resolve <IDependencyResolver>(), messagingEngine,
                                  new DefaultEndpointProvider(), true, registrations.ToArray()));
        }
        protected override void Load(ContainerBuilder builder)
        {
            Lykke.Messaging.Serialization.MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
            var rabbitMqSagasSettings = new global::RabbitMQ.Client.ConnectionFactory {
                Uri = _settings.CurrentValue.EthereumCore.Cqrs.RabbitConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>();

            var messagingEngine = new MessagingEngine(_log,
                                                      new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "SagasRabbitMq", new TransportInfo(rabbitMqSagasSettings.Endpoint.ToString(), rabbitMqSagasSettings.UserName, rabbitMqSagasSettings.Password, "None", "RabbitMq") }
            }),
                                                      new RabbitMqTransportFactory());

            var sagasEndpointResolver = new RabbitMqConventionEndpointResolver(
                "SagasRabbitMq",
                "messagepack",
                environment: "lykke",
                exclusiveQueuePostfix: "k8s");

            builder.Register(ctx =>
            {
                const string defaultRoute = "self";

                return(new CqrsEngine(_log,
                                      ctx.Resolve <IDependencyResolver>(),
                                      messagingEngine,
                                      new DefaultEndpointProvider(),
                                      true,
                                      Register.DefaultEndpointResolver(sagasEndpointResolver),
                                      Register.BoundedContext("blockchain.ethereum.core.api")
                                      .PublishingCommands(typeof(AssignErc223DepositToUserCommand))
                                      .To(EthereumBoundedContext.Name)
                                      .With(defaultRoute)));
            })
            .As <ICqrsEngine>()
            .SingleInstance()
            .AutoActivate();
        }
예제 #10
0
        private CqrsEngine CreateEngine(IComponentContext ctx, IMessagingEngine messagingEngine)
        {
            var rabbitMqConventionEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.MessagePack,
                environment: _settings.EnvironmentName);

            var engine = new CqrsEngine(
                _log,
                ctx.Resolve <IDependencyResolver>(),
                messagingEngine,
                new DefaultEndpointProvider(),
                true,
                Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                RegisterDefaultRouting(),
                RegisterContext(),
                Register.CommandInterceptors(new DefaultCommandLoggingInterceptor(_log)),
                Register.EventInterceptors(new DefaultEventLoggingInterceptor(_log)));

            engine.StartPublishers();

            return(engine);
        }
예제 #11
0
        private static CqrsEngine CreateEngine()
        {
            var sett             = SettingsUtil.Settings.IntegrationTestSettings.Cqrs;
            var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory
            {
                Uri = sett.ConnectionString
            };

            var log             = new LogToConsole();
            var messagingEngine = new MessagingEngine(log, new TransportResolver(new Dictionary <string, TransportInfo>
            {
                {
                    "RabbitMq",
                    new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName,
                                      rabbitMqSettings.Password, "None", "RabbitMq")
                }
            }), new RabbitMqTransportFactory());
            var rabbitMqConventionEndpointResolver =
                new RabbitMqConventionEndpointResolver("RabbitMq", "messagepack", environment: sett.EnvironmentName);

            return(new CqrsEngine(log, new DependencyResolver(), messagingEngine, new DefaultEndpointProvider(), true,
                                  Register.DefaultEndpointResolver(rabbitMqConventionEndpointResolver),
                                  RegisterBoundedContext(sett)));
        }
        private CqrsEngine CreateEngine(
            IComponentContext ctx,
            IMessagingEngine messagingEngine,
            ILogFactory logFactory)
        {
            const string defaultRoute = "self";

            var sagasMessagePackEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.MessagePack,
                environment: "lykke");

            var sagasProtobufEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.ProtoBuf,
                environment: "lykke");

            return(new CqrsEngine(
                       logFactory,
                       ctx.Resolve <IDependencyResolver>(),
                       messagingEngine,
                       new DefaultEndpointProvider(),
                       true,
                       Register.DefaultEndpointResolver(sagasProtobufEndpointResolver),

                       Register.EventInterceptors(new DefaultEventLoggingInterceptor(ctx.Resolve <ILogFactory>())),

                       Register.BoundedContext(HistoryBoundedContext.Name)

                       .ListeningEvents(typeof(CashoutCompletedEvent), typeof(CashinCompletedEvent))
                       .From(BitcoinBoundedContext.Name)
                       .On(defaultRoute)
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithProjection(typeof(TransactionHashProjection), BitcoinBoundedContext.Name)

                       .ListeningEvents(typeof(Lykke.Job.BlockchainCashinDetector.Contract.Events.CashinCompletedEvent))
                       .From(BlockchainCashinDetectorBoundedContext.Name)
                       .On(defaultRoute)
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithProjection(typeof(TransactionHashProjection), BlockchainCashinDetectorBoundedContext.Name)

                       .ListeningEvents(typeof(Lykke.Job.SiriusDepositsDetector.Contract.Events.CashinCompletedEvent))
                       .From(SiriusDepositsDetectorBoundedContext.Name)
                       .On(defaultRoute)
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithProjection(typeof(TransactionHashProjection), SiriusDepositsDetectorBoundedContext.Name)

                       .ListeningEvents(typeof(Lykke.Job.SiriusCashoutProcessor.Contract.Events.CashoutCompletedEvent))
                       .From(SiriusCashoutProcessorBoundedContext.Name)
                       .On(defaultRoute)
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithProjection(typeof(TransactionHashProjection), SiriusCashoutProcessorBoundedContext.Name)

                       .ListeningEvents(
                           typeof(Lykke.Job.BlockchainCashoutProcessor.Contract.Events.CashoutCompletedEvent),
                           typeof(Lykke.Job.BlockchainCashoutProcessor.Contract.Events.CrossClientCashoutCompletedEvent),
                           typeof(Lykke.Job.BlockchainCashoutProcessor.Contract.Events.CashoutsBatchCompletedEvent))
                       .From(BlockchainCashoutProcessorBoundedContext.Name)
                       .On(defaultRoute)
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithProjection(typeof(TransactionHashProjection), BlockchainCashoutProcessorBoundedContext.Name)

                       .ListeningCommands(typeof(CreateForwardCashinCommand), typeof(DeleteForwardCashinCommand))
                       .On("commands")
                       .WithCommandsHandler <ForwardWithdrawalCommandHandler>()
                       .PublishingEvents(typeof(ForwardCashinCreatedEvent), typeof(ForwardCashinDeletedEvent))
                       .With("events"),

                       Register.BoundedContext("tx-handler.ethereum.commands")
                       .ListeningCommands(typeof(SaveEthInHistoryCommand), typeof(ProcessEthCoinEventCommand),
                                          typeof(ProcessHotWalletErc20EventCommand))
                       .On("history")
                       .WithEndpointResolver(sagasMessagePackEndpointResolver)
                       .WithCommandsHandler <EthereumCommandHandler>()));
        }
        private CqrsEngine CreateEngine(
            IComponentContext ctx,
            IMessagingEngine messagingEngine,
            ILogFactory logFactory)
        {
            const string defaultPipeline = "commands";
            const string defaultRoute    = "self";

            var sagasMessagePackEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.MessagePack,
                environment: "lykke");

            var sagasProtobufEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.ProtoBuf,
                environment: "lykke");

            var engine = new CqrsEngine(
                logFactory,
                ctx.Resolve <IDependencyResolver>(),
                messagingEngine,
                new DefaultEndpointProvider(),
                true,
                Register.DefaultEndpointResolver(sagasMessagePackEndpointResolver),

                Register.EventInterceptors(new DefaultEventLoggingInterceptor(ctx.Resolve <ILogFactory>())),
                Register.CommandInterceptors(new DefaultCommandLoggingInterceptor(ctx.Resolve <ILogFactory>())),

                Register.BoundedContext(BoundedContext.ForwardWithdrawal)
                .ListeningCommands(
                    typeof(ProcessPaymentCommand),
                    typeof(RemoveEntryCommand),
                    typeof(RemoveEntryFromHistoryJobCommand),
                    typeof(RemoveEntryFromHistoryServiceCommand))
                .On(defaultRoute)
                .PublishingEvents(
                    typeof(PaymentEntryRemovedEvent),
                    typeof(CashInRemovedFromHistoryJobEvent),
                    typeof(CashInRemovedFromHistoryServiceEvent),
                    typeof(CashInProcesedEvent))
                .With(defaultPipeline)
                .WithCommandsHandler(typeof(CommandsHandler)),
                Register.Saga <PaymentSaga>("payment-saga")
                .ListeningEvents(
                    typeof(PaymentEntryRemovedEvent),
                    typeof(CashInRemovedFromHistoryJobEvent),
                    typeof(CashInRemovedFromHistoryServiceEvent),
                    typeof(CashInProcesedEvent))
                .From(BoundedContext.ForwardWithdrawal).On(defaultRoute)
                .PublishingCommands(
                    typeof(ProcessPaymentCommand),
                    typeof(RemoveEntryCommand),
                    typeof(RemoveEntryFromHistoryJobCommand),
                    typeof(RemoveEntryFromHistoryServiceCommand))
                .To(BoundedContext.ForwardWithdrawal).With(defaultPipeline)
                .PublishingCommands(
                    typeof(DeleteForwardCashinCommand))
                .To(HistoryBoundedContext.Name)
                .With(defaultPipeline)
                .WithEndpointResolver(sagasProtobufEndpointResolver),
                Register.Saga <CashoutsSaga>("cashouts-saga")
                .ListeningEvents(typeof(CashOutProcessedEvent))
                .From(PostProcessingBoundedContext.Name)
                .On(defaultRoute)
                .WithEndpointResolver(sagasProtobufEndpointResolver)
                .PublishingCommands(
                    typeof(CreateForwardCashinCommand))
                .To(HistoryBoundedContext.Name)
                .With(defaultPipeline)
                .WithEndpointResolver(sagasProtobufEndpointResolver),
                Register.DefaultRouting
                .PublishingCommands(typeof(RemoveEntryCommand))
                .To(BoundedContext.ForwardWithdrawal)
                .With(defaultPipeline));

            engine.StartPublishers();

            return(engine);
        }
예제 #14
0
        protected override void Load(ContainerBuilder builder)
        {
            Lykke.Messaging.Serialization.MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
            var rabbitMqSagasSettings = new RabbitMQ.Client.ConnectionFactory {
                Uri = _settings.CurrentValue.EthereumCore.Cqrs.RabbitConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>();

            var messagingEngine = new MessagingEngine(_log,
                                                      new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "SagasRabbitMq", new TransportInfo(rabbitMqSagasSettings.Endpoint.ToString(), rabbitMqSagasSettings.UserName, rabbitMqSagasSettings.Password, "None", "RabbitMq") }
            }),
                                                      new RabbitMqTransportFactory());

            var sagasEndpointResolver = new RabbitMqConventionEndpointResolver(
                "SagasRabbitMq",
                "messagepack",
                environment: "lykke",
                exclusiveQueuePostfix: "k8s");

            builder.RegisterType <Erc223DepositSagas>().SingleInstance().WithAttributeFiltering();

            builder.RegisterType <BlockPassCommandHandler>().SingleInstance().WithAttributeFiltering();
            builder.RegisterType <CashoutCommandHandler>().SingleInstance().WithAttributeFiltering();
            builder.RegisterType <TransferCommandHandler>().SingleInstance().WithAttributeFiltering();
            builder.RegisterType <Erc223DepositAssignCommandHandler>().SingleInstance().WithAttributeFiltering();

            builder.Register(ctx =>
            {
                const string defaultRoute    = "self";
                const string defaultPipeline = "commands";
                const string eventsRoute     = "events";

                return(new CqrsEngine(_log,
                                      ctx.Resolve <IDependencyResolver>(),
                                      messagingEngine,
                                      new DefaultEndpointProvider(),
                                      true,
                                      Register.DefaultEndpointResolver(sagasEndpointResolver),
                                      Register.BoundedContext(EthereumBoundedContext.Name)
                                      .PublishingEvents(typeof(CashoutCompletedEvent), typeof(TransferCompletedEvent))
                                      .With(eventsRoute)
                                      .ListeningCommands(typeof(StartCashoutCommand))
                                      .On(defaultRoute)
                                      .WithCommandsHandler <CashoutCommandHandler>()
                                      .ListeningCommands(typeof(StartTransferCommand))
                                      .On(defaultRoute)
                                      .WithCommandsHandler <TransferCommandHandler>()
                                      .ListeningCommands(typeof(AssignErc223DepositToUserCommand))
                                      .On(defaultRoute)
                                      .WithLoopback()
                                      .WithCommandsHandler <Erc223DepositAssignCommandHandler>()
                                      .PublishingEvents(typeof(Erc223DepositAssignedToUserEvent))
                                      .With(eventsRoute)
                                      .ListeningCommands(typeof(AddToPassWhiteListCommand))
                                      .On(defaultRoute)
                                      //.WithLoopback()
                                      .WithCommandsHandler <BlockPassCommandHandler>()
                                      .ProcessingOptions(defaultRoute).MultiThreaded(8).QueueCapacity(1024)
                                      .ProcessingOptions(eventsRoute).MultiThreaded(8).QueueCapacity(1024),

                                      Register.Saga <Erc223DepositSagas>($"{EthereumBoundedContext.Name}.saga")
                                      .ListeningEvents(typeof(Erc223DepositAssignedToUserEvent))
                                      .From(EthereumBoundedContext.Name)
                                      .On(defaultRoute)
                                      .PublishingCommands(typeof(AddToPassWhiteListCommand))
                                      .To(EthereumBoundedContext.Name)
                                      .With(defaultPipeline)
                                      ));
            })
            .As <ICqrsEngine>()
            .SingleInstance()
            .AutoActivate();
        }
예제 #15
0
        protected override void Load(ContainerBuilder builder)
        {
            Messaging.Serialization.MessagePackSerializerFactory.Defaults.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
            var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory
            {
                Uri = _settings.CurrentValue.SagasRabbitMqSettings.ConnectionString
            };

            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>().SingleInstance();

            builder.Register(c =>
                             new MessagingEngine(_log,
                                                 new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "RabbitMq", new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName, rabbitMqSettings.Password, "None", "RabbitMq") }
            }),
                                                 new RabbitMqTransportFactory()))
            .As <IMessagingEngine>();

            builder.RegisterType <ConfirmationCommandHandler>();

            builder.RegisterType <AssetsProjection>();
            builder.RegisterType <HistoryExportProjection>();
            builder.RegisterType <OperationsProjection>();
            builder.RegisterType <MarketDataProjection>()
            .WithParameter(TypedParameter.From(_settings.CurrentValue.CacheSettings.MarketDataCacheInterval));

            var protobufEndpointResolver = new RabbitMqConventionEndpointResolver(
                "RabbitMq",
                SerializationFormat.ProtoBuf,
                environment: "lykke",
                exclusiveQueuePostfix: _env);

            builder.Register(ctx =>
            {
                const string defaultRoute = "self";

                var engine = new CqrsEngine(
                    _log,
                    ctx.Resolve <IDependencyResolver>(),
                    ctx.Resolve <IMessagingEngine>(),
                    new DefaultEndpointProvider(),
                    true,
                    Register.DefaultEndpointResolver(new RabbitMqConventionEndpointResolver(
                                                         "RabbitMq",
                                                         SerializationFormat.MessagePack,
                                                         environment: "lykke",
                                                         exclusiveQueuePostfix: _env)),

                    Register.BoundedContext(WampHostBoundedContext.Name)
                    .ListeningEvents(
                        typeof(AssetCreatedEvent),
                        typeof(AssetUpdatedEvent),
                        typeof(AssetPairCreatedEvent),
                        typeof(AssetPairUpdatedEvent))
                    .From(BoundedContexts.Assets).On(defaultRoute)
                    .WithProjection(typeof(AssetsProjection), BoundedContexts.Assets)
                    .ListeningEvents(
                        typeof(ClientHistoryExportedEvent))
                    .From(HistoryExportBuilderBoundedContext.Name).On(defaultRoute)
                    .WithProjection(typeof(HistoryExportProjection), HistoryExportBuilderBoundedContext.Name)
                    .ListeningEvents(typeof(OperationFailedEvent), typeof(OperationConfirmedEvent), typeof(OperationCompletedEvent), typeof(OperationCorruptedEvent))
                    .From(OperationsBoundedContext.Name).On(defaultRoute)
                    .WithProjection(typeof(OperationsProjection), OperationsBoundedContext.Name)
                    .ListeningEvents(typeof(MarketDataChangedEvent))
                    .From(MarketDataBoundedContext.Name).On(defaultRoute)
                    .WithProjection(typeof(MarketDataProjection), MarketDataBoundedContext.Name)
                    .ListeningCommands(typeof(RequestConfirmationCommand)).On("commands")
                    .WithEndpointResolver(protobufEndpointResolver)
                    .WithCommandsHandler <ConfirmationCommandHandler>()
                    );
                engine.StartPublishers();
                return(engine);
            })
            .As <ICqrsEngine>()
            .SingleInstance()
            .AutoActivate();
        }