Esempio n. 1
0
        public void when_sending_message_then_can_receive_it()
        {
            var             sender  = new TopicSender(this.settings, this.topic);
            BrokeredMessage message = null;
            var             data    = new Data {
                Id = Guid.NewGuid(), Title = "Foo"
            };

            using (var receiver = new SubscriptionReceiver(this.settings, this.topic, this.subscription))
            {
                var signal = new ManualResetEventSlim();

                receiver.MessageReceived += (o, e) =>
                {
                    message = e.Message;
                    signal.Set();
                };

                receiver.Start();

                sender.Send(new BrokeredMessage(data));

                signal.Wait();
            }

            Assert.NotNull(message);

            var received = message.GetBody <Data>();

            Assert.Equal(data.Id, received.Id);
            Assert.Equal(data.Title, received.Title);
        }
        public void when_sending_message_then_can_receive_it()
        {
            var  sender = new TopicSender(this.Settings, this.Topic);
            Data data   = new Data {
                Id = Guid.NewGuid(), Title = "Foo"
            };
            Data received = null;

            using (var receiver = new SubscriptionReceiver(this.Settings, this.Topic, this.Subscription))
            {
                var signal = new ManualResetEventSlim();

                receiver.Start(
                    m =>
                {
                    received = m.GetBody <Data>();
                    signal.Set();
                    return(MessageReleaseAction.CompleteMessage);
                });

                sender.SendAsync(() => new BrokeredMessage(data));

                signal.Wait();
            }

            Assert.NotNull(received);
            Assert.Equal(data.Id, received.Id);
            Assert.Equal(data.Title, received.Title);
        }
        public void when_receiving_not_registered_command_then_ignores()
        {
            var receiver  = new SubscriptionReceiver(this.Settings, this.Topic, this.Subscription);
            var processor = new CommandProcessor(receiver, new BinarySerializer());
            var bus       = new CommandBus(new TopicSender(this.Settings, this.Topic), new MetadataProvider(), new BinarySerializer());

            var e       = new ManualResetEventSlim();
            var handler = new FooCommandHandler(e);

            receiver.MessageReceived += (sender, args) => e.Set();

            processor.Register(handler);

            processor.Start();

            try
            {
                bus.Send(new BarCommand());

                e.Wait();
                // Give the other event handler some time.
                Thread.Sleep(100);

                Assert.False(handler.Called);
            }
            finally
            {
                processor.Stop();
            }
        }
        public void when_starting_twice_then_throws()
        {
            var receiver = new SubscriptionReceiver(this.Settings, this.Topic, this.Subscription);

            receiver.Start();

            Assert.Throws <InvalidOperationException>(() => receiver.Start());
        }
Esempio n. 5
0
        public void when_starting_twice_then_ignores_second_request()
        {
            var receiver = new SubscriptionReceiver(Settings, Topic, Subscription);

            receiver.Start(m => MessageReleaseAction.CompleteMessage);

            receiver.Start(m => MessageReleaseAction.CompleteMessage);
        }
        public void when_starting_twice_then_ignores_second_request()
        {
            var receiver = new SubscriptionReceiver(this.Settings, this.Topic, this.Subscription);

            receiver.Start();

            receiver.Start();
        }
Esempio n. 7
0
        static void TestProcessEvent()
        {
            SubscriptionClient   subscriptionClient = SubscriptionClient.CreateFromConnectionString(serviceBusConnectionString, orderEventTopicPath, orderEventSubscription);
            SubscriptionReceiver receiver           = new SubscriptionReceiver(subscriptionClient);
            ITextSerializer      serializer         = new JsonTextSerializer();

            EventProcessor eventProcessor = new EventProcessor(receiver, serializer);

            eventProcessor.Register(new OrderEventHandler());
            eventProcessor.Start();
        }
Esempio n. 8
0
        static void TestProcessCommand()
        {
            SubscriptionClient   subscriptionClient = SubscriptionClient.CreateFromConnectionString(serviceBusConnectionString, commandTopicPath, commandHandlerSubscription);
            SubscriptionReceiver receiver           = new SubscriptionReceiver(subscriptionClient);
            ITextSerializer      serializer         = new JsonTextSerializer();

            CommandProcessor orderCommandProcessor = new CommandProcessor(receiver, serializer);

            orderCommandProcessor.Register(new OrderCommandHandler());

            orderCommandProcessor.Start();
        }
    public void PreparePubSub(IRawEndpoint endpoint, out IPublishRouter publishRouter, out SubscriptionReceiver subscriptionReceiver, out SubscriptionForwarder subscriptionForwarder)
    {
        var transport = endpoint.Settings.Get <TransportInfrastructure>();

        if (transport.OutboundRoutingPolicy.Publishes == OutboundRoutingType.Multicast)
        {
            publishRouter         = new NativePublishRouter(typeGenerator);
            subscriptionReceiver  = new NullSubscriptionReceiver();
            subscriptionForwarder = new NativeSubscriptionForwarder(endpoint.SubscriptionManager, typeGenerator, endpointInstances);
        }
        else
        {
            if (subscriptionPersistence == null)
            {
                throw new Exception("Subscription storage has not been configured. Use 'UseSubscriptionPersistence' method to configure it.");
            }
            publishRouter         = new MessageDrivenPublishRouter(subscriptionPersistence, distributionPolicy);
            subscriptionReceiver  = new StorageDrivenSubscriptionReceiver(subscriptionPersistence);
            subscriptionForwarder = new MessageDrivenSubscriptionForwarder(endpointInstances);
        }
    }
        public void when_disposing_not_started_then_no_op()
        {
            var receiver = new SubscriptionReceiver(this.Settings, this.Topic, this.Subscription);

            receiver.Dispose();
        }
Esempio n. 11
0
        public void when_stopping_without_starting_then_ignores_request()
        {
            var receiver = new SubscriptionReceiver(Settings, Topic, Subscription);

            receiver.Stop();
        }