コード例 #1
0
        public void Bus_SimpleSubscribtion_CallReceivedOnImplementationInstace()
        {
            ManualResetEvent ev = new ManualResetEvent(false);

            SimpleImplementation implementation = new SimpleImplementation(ev);

            using (IBus bus = new RabbitMQBus())
            {
                using (ISubscription subscription = bus.RegisterSubscription(implementation))
                {
                    subscription.Open();

                    using (IPublisher publisher = bus.CreatePublisher())
                    {
                        Person person = new Person {
                            Id = 5
                        };

                        BusMessage <Person> busMessage = new BusMessage <Person>
                        {
                            Data = person
                        };

                        busMessage.Headers.Add(new BusHeader
                        {
                            Name  = "Header",
                            Value = "Value"
                        });

                        publisher.Send(busMessage);

                        bool waitOne = ev.WaitOne(TimeSpan.FromSeconds(5));

                        waitOne.Should().BeTrue();

                        person.ShouldBeEquivalentTo(implementation.Person);
                    }
                }
            }
        }
コード例 #2
0
        public void Bus_SimpleSubscription_CallReceivedOnImplementationInstace()
        {
            ManualResetEvent ev = new ManualResetEvent(false);

            SimpleImplementation implementation = new SimpleImplementation(ev);

            using (IBus bus = new MessageBus.Core.RabbitMQBus())
            {
                using (ISubscription subscription = bus.RegisterSubscription(implementation, c => c.SetReceiveSelfPublish()))
                {
                    subscription.Open();

                    using (IPublisher publisher = bus.CreatePublisher())
                    {
                        Person person = new Person {Id = 5};

                        BusMessage<Person> busMessage = new BusMessage<Person>
                            {
                                Data = person
                            };

                        busMessage.Headers.Add(new BusHeader
                            {
                                Name = "Header",
                                Value = "Value"
                            });

                        publisher.Send(busMessage);

                        bool waitOne = ev.WaitOne(TimeSpan.FromSeconds(5));

                        waitOne.Should().BeTrue();

                        person.ShouldBeEquivalentTo(implementation.Person);
                    }
                }
            }
        }