Esempio n. 1
0
        public void Init()
        {
            _exchange   = "TestExchange";
            _queue      = "TestQueue";
            _ttlQueue   = "TTLTestQueue";
            _routingKey = "RouteMe";

            var rabbitConnection = ObservableConnectionFactory.Create(f => f.WithLogger(new RabbitMqConsoleLogger())
                                                                      .WithUserName("test")
                                                                      .WithPassword("test")
                                                                      .WithHostName(Environment.MachineName));

            _argList = new Dictionary <string, object>
            {
                { "x-message-ttl", 60000 }
            };


            rabbitConnection.SetUp(s => s.Exchange("EVERYTHING").Topic.BoundToQueue("LEFTOVERS"));
            rabbitConnection.SetUp(s => s.Exchange(_exchange).Fanout.BoundToQueue(_queue, null));
            rabbitConnection.SetUp(s => s.Exchange(_exchange).Fanout.BoundToQueue(_ttlQueue, _argList));


            _queueConnection    = rabbitConnection.Queue(_queue);
            _ttlQueueConnection = rabbitConnection.Queue(_ttlQueue);

            Enumerable.Range(0, 10).ToList().ForEach(i =>
            {
                Console.WriteLine("Publishing {0}", i);
                rabbitConnection.Exchange(_exchange)
                .Publish(new MyMessage {
                    Greeting = "Message: " + i
                });
            });
        }
Esempio n. 2
0
        public void Init(IKernel kernel, IConfiguration facilityConfig)
        {
            _kernel = kernel;
            _kernel.ComponentModelCreated += ComponentModelCreated;

            _connectionRegistration = Component.For <IObservableConnection>()
                                      .UsingFactoryMethod(
                () =>
            {
                return(ObservableConnectionFactory.Create(
                           c =>
                {
                    foreach (var customization in _customizations)
                    {
                        customization.Invoke(c);
                    }
                }));
            })
                                      .NamedAutomatically(Guid.NewGuid().ToString());
            _kernel.Register(_connectionRegistration);

            _kernel.Register(Component.For <ISerializer>().Instance(_configuredSerializer));

            foreach (var interceptor in _interceptingTypes)
            {
                _kernel.Register(Component.For(interceptor.Value.ToArray()).ImplementedBy(interceptor.Key).LifeStyle.Singleton);
            }
        }
Esempio n. 3
0
        public void ApiTest()
        {
            var connection = ObservableConnectionFactory.Create();

            connection.SetUp(s => s.Exchange(_exchange).Fanout.BoundToQueue(_queue, null));

            var queueconnection = connection.Queue("MessageQueue");
            var exchange        = connection.Exchange(_exchange);

            Enumerable.Range(0, 100).ToList().ForEach(i => exchange.Publish(new MyMessage
            {
                Greeting = string.Format("Hello message: {0}", i)
            }));

            queueconnection
            .Open()
            .Stream <MyMessage>();
        }