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


C# MessageBus.SendAsync方法代码示例

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


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

示例1: VerifyMessagesArePublished

        public async Task VerifyMessagesArePublished()
        {
            // Setup the message bus.
            var cs = Any.String();
            var publisher = new MockPublisher();
            var mbf = new MockMessageBusFactory { Publisher = publisher };
            var mbd = new MessageBusDescription { ConnectionString = cs, Factory = mbf };
            var bus = new MessageBus(mbd);
            var entity = Any.String();

            Assert.IsFalse(
                publisher.IsInitialized, 
                "The publisher should not be initialized before it is called the first time.");

            // Send a message on the bus.
            var message = new MockMessage
                              {
                                  CorrelationKey = Any.String(), 
                                  Message = Any.String(), 
                                  MessageKey = Any.String(), 
                                  PartitionKey = Any.String(), 
                                  Properties =
                                      new Dictionary<string, object> { { Any.String(), Any.String() } }
                              };
            await bus.SendAsync(entity, message);

            Assert.IsTrue(
                publisher.IsInitialized, 
                "The publisher should be initialized after it is called the first time.");
            Assert.AreEqual(publisher.Description.ConnectionString, cs);
            Assert.AreEqual(publisher.Description.Entity, entity);

            await bus.CloseAsync();

            Assert.IsTrue(publisher.IsClosed, "The publisher should be closed.");

            // Verify the message sent.
            Assert.AreEqual(publisher.IsInitialized, true);
            Assert.AreEqual(publisher.Message.CorrelationKey, message.CorrelationKey);
            Assert.AreEqual(publisher.Message.Message, message.Message);
            Assert.AreEqual(publisher.Message.MessageKey, message.MessageKey);
            Assert.AreEqual(publisher.Message.PartitionKey, message.PartitionKey);
        }
开发者ID:blinds52,项目名称:Microsoft-Message-Bridge,代码行数:43,代码来源:MessageBusFixture.cs

示例2: SendMessage

 /// <summary>
 /// Sends the message.
 /// </summary>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="bus">
 /// The bus.
 /// </param>
 private static void SendMessage(string entity, string message, MessageBus bus)
 {
     Console.WriteLine("Sending message: {0}", message);
     bus.SendAsync(entity, new EventMessage { Message = message, MessageKey = Guid.NewGuid().ToString() }).Wait();
 }
开发者ID:blinds52,项目名称:Microsoft-Message-Bridge,代码行数:17,代码来源:PublicationHandler.cs


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