Exemple #1
0
        public async Task SentPaymentReceivedEvent(double moneyAmount)
        {
            var message = new PaymentReceivedContract
            {
                MoneyAmount = moneyAmount, UserName = "******", DateTimeOffset = DateTimeOffset.Now
            };

            var hostConfig = new MassTransitConfiguration();

            _configuration.GetSection("MassTransit").Bind(hostConfig);
            var endpoint = await _sendEndpointProvider.GetSendEndpoint(hostConfig.GetQueueAddress("test-queue-name"));

            await endpoint.Send(message);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <PaymentReceivedProducer>();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMassTransit(isp =>
            {
                var hostConfig = new MassTransitConfiguration();
                Configuration.GetSection("MassTransit").Bind(hostConfig);

                return(Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    var host = cfg.Host(
                        new Uri(hostConfig.RabbitMqAddress),
                        h =>
                    {
                        h.Username(hostConfig.UserName);
                        h.Password(hostConfig.Password);
                    });

                    cfg.Durable = hostConfig.Durable;
                    cfg.PurgeOnStartup = hostConfig.PurgeOnStartup;
                }));
            });
        }