Exemplo n.º 1
0
        public void TestAddSameNameChannelPool()
        {
            ServiceCollection services = new ServiceCollection();

            services.AddOptions();
            services.Configure <RabbitMQOptionCollection>(a =>
            {
                a.TryAdd(new RabbitMQOption
                {
                    HostName    = "localhost",
                    Port        = 5672,
                    UserName    = "******",
                    Password    = "******",
                    VirtualHost = "/",
                    Name        = "name1"
                });
            });
            services.Configure <RabbitMQOptionCollection>(a =>
            {
                a.TryAdd(new RabbitMQOption
                {
                    HostName    = "localhost",
                    Port        = 5672,
                    UserName    = "******",
                    Password    = "******",
                    VirtualHost = "/",
                    Name        = "name1"
                });
            });
            services.AddRabbitMQProducerService();
            services.AddSingleton <TestMqTransporter>();
            ServiceProvider serviceProvider = services.BuildServiceProvider();

            TestMqTransporter transport = serviceProvider.GetService <TestMqTransporter>();
        }
Exemplo n.º 2
0
        public async Task SingleHost()
        {
            ServiceCollection services = new ServiceCollection();

            services.AddOptions();
            services.Configure <RabbitMQOptionCollection>(a =>
            {
                a.Add(new RabbitMQOption
                {
                    HostName    = "localhost",
                    Port        = 5672,
                    UserName    = "******",
                    Password    = "******",
                    VirtualHost = "/",
                });
            });
            services.AddRabbitMQProducerService();
            services.AddSingleton <TestMqTransporter>();
            ServiceProvider serviceProvider = services.BuildServiceProvider();
            //IMessageProducer transport = serviceProvider.GetService<IMessageProducer>();

            TestMqTransporter transport = serviceProvider.GetService <TestMqTransporter>();
            var result = await transport.SendTestMessageAsync(new TestModel { UserId = Guid.NewGuid() });

            _output.WriteLine(result.ToString());
            //for (int i = 0; i < 1000000; i++)
            //{
            //	ProducerResult taskresult = await transport.SendAsync(new Message<string>(
            //	new Dictionary<string, string> {
            //			{ Generic.Headers.Exchange, "test.ex.v1" },
            //			{ Generic.Headers.RoutingKey, "test.rk.v1" },
            //	}, "你好呀"));
            //}
            //Console.ReadKey();
        }
Exemplo n.º 3
0
        public async Task Test()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            services.AddOptions();
            services.Configure <RabbitMQOptionCollection>(a =>
            {
                a.Add(new RabbitMQOption
                {
                    HostName    = "localhost",
                    Port        = 5672,
                    UserName    = "******",
                    Password    = "******",
                    VirtualHost = "/",
                });
            });

            services.Configure <RabbitMQOptionCollection>(a =>
            {
                a.Add(new RabbitMQOption
                {
                    HostName    = "localhost",
                    Port        = 5672,
                    UserName    = "******",
                    Password    = "******",
                    VirtualHost = "test",
                    Name        = "",
                });
            });
            services.AddRabbitMQProducerService();
            services.AddSingleton <TestMqTransporter>();
            ServiceProvider   serviceProvider = services.BuildServiceProvider();
            TestMqTransporter transport       = serviceProvider.GetService <TestMqTransporter>();

            await transport.SendTestMessageAsync(new TestModel { UserId = Guid.NewGuid() });
        }