当前位置: 首页>>代码示例>>C#>>正文


C# MessageBus.SubscriberFor方法代码示例

本文整理汇总了C#中MessageBus.SubscriberFor方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBus.SubscriberFor方法的具体用法?C# MessageBus.SubscriberFor怎么用?C# MessageBus.SubscriberFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageBus的用法示例。


在下文中一共展示了MessageBus.SubscriberFor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanFindExplicitTypes

        public void CanFindExplicitTypes()
        {
            var bus = new MessageBus();
            bus.SubscriberFor<TestMessageBase>(m => { });
            bus.SubscriberFor<TestMessageTypeA>(m => { });
            bus.SubscriberFor<TestMessageTypeB>(m => { });

            bus.FindSubscribersOfExplicitType(typeof(TestMessageTypeA))
                .Should().HaveCount(1);
            bus.FindSubscribersOfExplicitType(typeof(TestMessageBase))
                .Should().HaveCount(1);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:12,代码来源:MessageBusHasSubscribersTest.cs

示例2: HeavyLoadTest

        public void HeavyLoadTest()
        {
            const int REPEATER_COUNT = 10;
              const int MESSAGE_COUNT = 200;

              // Arrange
              var bus = new MessageBus();

              var receivers = new MessageRepeater[REPEATER_COUNT];
              for (var i = 0; i < REPEATER_COUNT; i++)
              {
            receivers[i] = new MessageRepeater(bus, i);
            bus.SubscriberFor<RepeatingMessage>(receivers[i].Receive);
              }

              // Act
              var messages = new RepeatingMessage[MESSAGE_COUNT];
              for (var i = 0; i < MESSAGE_COUNT; i++)
              {
            messages[i] = new RepeatingMessage();
            bus.SendMessage(messages[i]);
              }

              // Assert
              var finished = false;
              while (!finished)
              {
            System.Threading.Thread.Sleep(500);
            var count = messages.Count(m => m.Counter == REPEATER_COUNT);
            Console.WriteLine(count);
            if (count == MESSAGE_COUNT)
              finished = true;
              }
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:34,代码来源:MessageBus_CopesWithHeavyLoad.cs

示例3: TrueWithExactMatch

 public void TrueWithExactMatch()
 {
     var bus = new MessageBus();
     bus.SubscriberFor<Message>(m => { });
     bus.HasSubscriberFor<Message>()
         .Should().BeTrue(
             "subscriber for type was added");
 }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:8,代码来源:MessageBusHasSubscribersTest.cs

示例4: TrueWithDerivedType

 public void TrueWithDerivedType()
 {
     var bus = new MessageBus();
     bus.SubscriberFor<TestMessageBase>(m => { });
     bus.HasSubscriberFor<TestMessageTypeA>()
         .Should().BeTrue(
             "subscriber for super type was added");
 }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:8,代码来源:MessageBusHasSubscribersTest.cs

示例5: FalseWithSuperType

 public void FalseWithSuperType()
 {
     var bus = new MessageBus();
     bus.SubscriberFor<TestMessageTypeA>(m => { });
     bus.HasSubscriberFor<TestMessageBase>()
         .Should().BeFalse(
             "subscriber for derived type was added");
 }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:8,代码来源:MessageBusHasSubscribersTest.cs

示例6: FalseWithNonMatch

 public void FalseWithNonMatch()
 {
     var bus = new MessageBus();
     bus.SubscriberFor<TestMessageTypeA>(m => { });
     bus.HasSubscriberFor<TestMessageTypeB>()
         .Should().BeFalse(
             "no subscriber for type was added");
 }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:8,代码来源:MessageBusHasSubscribersTest.cs

示例7: SetUp

        public void SetUp()
        {
            bus = new MessageBus();

            var receiverForA = new TestMessageReceiver("receiverForA");
            var receiverForB = new TestMessageReceiver("receiverForB");
            var receiverForAll = new TestMessageReceiver("receiverForAll");

            subscriberA = bus.SubscriberFor<TestMessageTypeA>(receiverForA.Receive);
            subscriberB = bus.SubscriberFor<TestMessageTypeB>(receiverForB.Receive);
            subscriberC = bus.SubscriberFor<TestMessageBase>(receiverForAll.Receive);
            testMessageA = new TestMessageTypeA();
            testMessageB = new TestMessageTypeB();
            testMessageC = new TestMessageTypeC();
            bus.SendMessage(testMessageB);
            bus.SendMessage(testMessageC);

            Thread.Sleep(100);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:19,代码来源:MessageBusTests.cs

示例8: IncrementsWhenAddingSubscribers

        public void IncrementsWhenAddingSubscribers()
        {
            var bus = new MessageBus();

              if (bus.GetSubscriberCount != 0)
            Assert.Inconclusive("SubscriberCount should start at 0");

              bus.SubscriberFor<Message>(_ => { });

              bus.GetSubscriberCount.Should().Be(1);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:11,代码来源:MessageBus_SubscriberCount.cs

示例9: RetainsSubscriptions

        public void RetainsSubscriptions()
        {
            // Arrange
              var bus = new MessageBus();

              // Act
              for (var i = 0; i < 1000; i++)
            bus.SubscriberFor<Message>(NoAction);

              // Assert
              bus.GetSubscriberCount
              .Should().Be(1000);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:13,代码来源:MessageBus_SubscriberCount.cs

示例10: CopesWithHighConcurrencySubscriptions

        public void CopesWithHighConcurrencySubscriptions()
        {
            // Arrange
              var bus = new MessageBus();

              // Act
              for (var i = 0; i < 1000; i++)
            bus.SubscriberFor<Message>(NoAction);

              // Assert
              bus.GetSubscriberCount
              .Should().Be(1000);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:13,代码来源:MessageBus_SubscriberCount.cs

示例11: WhenTheyAreStillBeingReferenced

        public void WhenTheyAreStillBeingReferenced()
        {
            // Arrange
              var subscribers = new Subscriber<TestMessageTypeA>[100];
              var bus = new MessageBus();
              for (var i = 0; i < 100; i++)
              {
            subscribers[i] = bus.SubscriberFor<TestMessageTypeA>(NoAction);
              }

              // Act
              GC.Collect();

              // Assert
              bus.GetSubscriberCount.Should().Be(100);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:16,代码来源:MessageBus_RetainsSubscribers.cs

示例12: DecrementsWhenSubscribersAreGarbageCollected

        public void DecrementsWhenSubscribersAreGarbageCollected()
        {
            var bus = new MessageBus();
              // ReSharper disable once NotAccessedVariable
              var subscriber = bus.SubscriberFor<Message>(NoAction);

              Wait.For(() => bus.GetSubscriberCount == 1);

              // ReSharper disable once RedundantAssignment
              subscriber = null;
              GC.Collect();

              Wait.For(() => bus.GetSubscriberCount == 0);

              bus.GetSubscriberCount.Should().Be(0);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:16,代码来源:MessageBus_SubscriberCount.cs

示例13: WhenSubscriberThrowsException

        public void WhenSubscriberThrowsException()
        {
            // Arrange
              var bus = new MessageBus();
              bus.SubscriberFor<Message>(
            m =>
            {
              throw new Exception();
            });
              var exceptions = new Collection<AggregateException>();
              bus.ExceptionListener = exceptions.Add;

              // Act
              bus.SendMessage(new TestMessageTypeA());

              // Assert
              while (exceptions.Count == 0)
              {
            Thread.Sleep(100);
              }
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:21,代码来源:MessageBus_HandlesExceptions.cs


注:本文中的MessageBus.SubscriberFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。