示例#1
0
        static void Main(string[] args)
        {
            string route = "listener2";

            if (args.Any())
            {
                route = args[0];
            }

            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, new MessagingDependencyRegistrator())
                                     .RegisterHandler <DefaultHandler>()
                                     .RegisterHandler <AnotherDefaultHandler>();

            var builder    = configurator.Build(autofacRegistrator.CreateResolver());
            var subscriber = builder.GetSubscriber();

            subscriber.Subscribe <DefaultHandler, DomainMessage>();
            subscriber.Subscribe <AnotherDefaultHandler, AnotherDomainMessage>();

            var mongoMessageListener = builder.GetListener();

            mongoMessageListener.Start(route, CancellationToken.None).Wait();
            Console.WriteLine($"started listener {route}");
            Console.ReadLine();
        }
        public void Setup()
        {
            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, GetRegistrtor());

            configurator
            .SetConfigurationProvider(TestMessagingConfiguration.Create())
            .SetTopicProvider <TestTopicNameProvider>()
            .RegisterHandler <TestHandler>()
            .RegisterHandler <SlightlyDifferentTestHandler>()
            .RegisterHandler <ResendHandler>()
            .RegisterHandler <TimeConsumingHandler>();
            Resolver = autofacRegistrator.CreateResolver();
            Builder  = configurator.Build(Resolver);
            ClearDb();
        }
示例#3
0
        static async Task DoStuff()
        {
            var autofacRegistrator = new AutofacRegistrator();
            var configurator       = new QueueConfigurator(autofacRegistrator, new MessagingDependencyRegistrator());

            var builder   = configurator.Build(autofacRegistrator.CreateResolver());
            var publisher = builder.GetPublisher();

            while (true)
            {
                try
                {
                    var rnd  = new Random(DateTime.Now.Millisecond);
                    var id   = rnd.Next();
                    var guid = Guid.NewGuid().ToString();
                    if (id % 2 == 0)
                    {
                        if (id % 4 == 0)
                        {
                            var message = new DomainMessage(guid, "exception");
                            await publisher.PublishAsync(message);
                        }
                        else
                        {
                            var message = new DomainMessage(guid, rnd.Next().ToString());
                            await publisher.PublishAsync(message);
                        }
                    }
                    else
                    {
                        var message = new AnotherDomainMessage(guid, rnd.Next().ToString(), "waddap indeed");
                        await publisher.PublishAsync(message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    await Task.Delay(500);
                }
            }
        }