Exemplo n.º 1
0
        /// <summary>
        /// 入口
        /// </summary>
        /// <param name="args">参数</param>
        static void Main(string[] args)
        {
            var service          = new ServiceCollection();
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <HelloIntegrationEventHandler>();
            containerBuilder.RegisterType <HelloDynamicIntegrationEventHandler>();
            service.AddLogging(log => log.AddConsole());
            var provider = service.BuildServiceProvider();

            var container  = containerBuilder.Build();
            var factory    = new ConnectionFactory();
            var manager    = new InMemoryEventBusSubscriptionsManager();
            var connection = new DefaultIRabbitMQPersisterConnection(factory, provider.GetRequiredService <ILogger <DefaultIRabbitMQPersisterConnection> >());
            var eventbus   = new EventBusRabbitMQ.EventBusRabbitMQ(connection, provider.GetRequiredService <ILogger <EventBusRabbitMQ.EventBusRabbitMQ> >(), container.BeginLifetimeScope(), manager, "EventBusSubscribTest");

            eventbus.Subscribe <HelloIntegrationEvent, HelloIntegrationEventHandler>();
            eventbus.SubscrbieDynamic <HelloDynamicIntegrationEventHandler>("HelloIntegrationEvent");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 入口
        /// </summary>
        /// <param name="args">参数</param>
        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();
            var factory          = new ConnectionFactory()
            {
                HostName = "localhost", UserName = "******", Password = "******"
            };

            var service = new ServiceCollection();

            service.AddLogging(log => log.AddConsole());
            var provide = service.BuildServiceProvider();

            var container        = containerBuilder.Build();
            var connection       = new EventBusRabbitMQ.DefaultIRabbitMQPersisterConnection(factory, provide.GetRequiredService <ILogger <EventBusRabbitMQ.DefaultIRabbitMQPersisterConnection> >());
            var eventbusrabbitMQ = new EventBusRabbitMQ.EventBusRabbitMQ(connection, provide.GetRequiredService <ILogger <EventBusRabbitMQ.EventBusRabbitMQ> >(), container.BeginLifetimeScope(), new InMemoryEventBusSubscriptionsManager(), "EventBusPublishTest");

            var hello = new HelloIntegrationEvent("title", "content");

            eventbusrabbitMQ.Publish(hello);

            Console.WriteLine("已发布");
            Console.Read();
        }