private void SetProjectionListener(PaymentsRepository repository, IServiceCollection services)
        {
            var config = new RabbitMqConfig();

            configuration.GetSection("RabbitMq").Bind(config);

            var logger   = services.BuildServiceProvider().GetService <ILogger <RabbitMqPublisher> >();
            var rabbitMq = new RabbitMqChannelFactory().CreateReadChannel <Models.Payment, string>(config, "PaymentsRead", logger);

            rabbitMq.Received += (sender, projection) =>
            {
                if (projection.Upsert != null && projection.Upsert.Length > 0)
                {
                    repository.Upsert(projection.Upsert);
                }
                if (projection.Upsert != null && projection.Upsert.Length == 0)
                {
                    repository.Clear();
                }
                if (projection.Remove != null)
                {
                    repository.Remove(projection.Remove);
                }
            };
        }
 public RabbitMqMessageStore(RabbitMqChannelFactory channelFactory, ILogger <RabbitMqMessageStore> logger)
 {
     _logger             = logger;
     _channel            = channelFactory.CreateChannel();
     _props              = _channel.CreateBasicProperties();
     _props.DeliveryMode = 2;
     _props.ContentType  = "plain/text";
 }
Example #3
0
        public static RabbitMqPublisher AddRabbitMqPublisher(this IServiceCollection collection, IConfiguration configuration, string serviceName)
        {
            var config = new RabbitMqConfig();

            configuration.GetSection("RabbitMq").Bind(config);
            var logger    = collection.BuildServiceProvider().GetService <ILogger <RabbitMqPublisher> >();
            var publisher = new RabbitMqChannelFactory().CreateWriteChannel(config, serviceName, logger);

            collection.AddSingleton(publisher);
            return(publisher);
        }