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


C# IMessageConsumer.Receive方法代码示例

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


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

示例1: ConsumeNMessages

 /// <summary>
 /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages
 /// are text messages with contents equal to the specified message body.
 /// </summary>
 ///
 /// <param name="n">The number of messages to consume.</param>
 /// <param name="body">The body text to match against all messages.</param>
 /// <param name="consumer">The message consumer to recieve the messages on.</param>
 public static void ConsumeNMessages(int n, string body, IMessageConsumer consumer)
 {
     IMessage msg;
     
     // Try to receive n messages.
     for (int i = 0; i < n; i++)
     {
         msg = consumer.Receive(RECEIVE_WAIT);
         Assert.IsNotNull(msg, "Consumer did not receive message number: " + i);
         Assert.AreEqual(body, ((ITextMessage)msg).Text, "Incorrect Message recevied on consumer1.");
     }
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:20,代码来源:BaseMessagingTestFixture.cs

示例2: TestCloseConsumerBeforeCommit

        public void TestCloseConsumerBeforeCommit()
        {
            ITextMessage[] outbound = new ITextMessage[] {
                session.CreateTextMessage("First IMessage"),
                session.CreateTextMessage("Second IMessage")};

            // lets consume any outstanding messages from prev test runs
            BeginTx();
            bool needCommit = false;
            while(consumer.ReceiveNoWait() != null)
            {
                needCommit = true;
            }

            if(needCommit)
            {
                CommitTx();
            }

            // sends the messages
            BeginTx();
            producer.Send(outbound[0]);
            producer.Send(outbound[1]);
            CommitTx();

            BeginTx();
            ITextMessage message = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
            Assert.AreEqual(outbound[0].Text, message.Text);
            // Close the consumer before the Commit. This should not cause the
            // received message to Rollback.
            consumer.Close();
            CommitTx();

            // Create a new consumer
            consumer = CreateMessageConsumer();

            BeginTx();
            message = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
            Assert.IsNotNull(message);
            Assert.AreEqual(outbound[1].Text, message.Text);
            CommitTx();
        }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:42,代码来源:AMQTransactionTestSupport.cs

示例3: ConsumeNMessagesOnly

 /// <summary>
 /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages
 /// are text messages with contents equal to the specified message body.
 /// </summary>
 ///
 /// <param name="n">The number of messages to consume.</param>
 /// <param name="body">The body text to match against all messages.</param>
 /// <param name="consumer">The message consumer to recieve the messages on.</param>
 public static void ConsumeNMessagesOnly(int n, string body, IMessageConsumer consumer)
 {
     ConsumeNMessages(n, body, consumer);
     
     // Check that one more than n cannot be received.
     IMessage msg = consumer.Receive(RECEIVE_WAIT);
     Assert.IsNull(msg, "Consumer got more messages than the number requested (" + n + ").");
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:16,代码来源:BaseMessagingTestFixture.cs

示例4: DoReceive

 /// <summary>
 /// Receive a message.
 /// </summary>
 /// <param name="session">The session to operate on.</param>
 /// <param name="consumer">The consumer to receive with.</param>
 /// <returns>The Message received, or <code>null</code> if none</returns>
 protected virtual Message DoReceive(ISession session, IMessageConsumer consumer)
 {
     try
     {
         long timeout = ReceiveTimeout;
         EmsResourceHolder resourceHolder =
         (EmsResourceHolder)TransactionSynchronizationManager.GetResource(ConnectionFactory);
         if (resourceHolder != null && resourceHolder.HasTimeout)
         {
             timeout = Convert.ToInt64(resourceHolder.TimeToLiveInMilliseconds);
         }
         Message message = (timeout > 0)
                               ? consumer.Receive(timeout)
                               : consumer.Receive();
         if (session.Transacted)
         {
             // Commit necessary - but avoid commit call is Session transaction is externally coordinated.
             if (IsSessionLocallyTransacted(session))
             {
                 // Transacted session created by this template -> commit.
                 EmsUtils.CommitIfNecessary(session);
             }
         }
         else if (IsClientAcknowledge(session))
         {
             // Manually acknowledge message, if any.
             if (message != null)
             {
                 message.Acknowledge();
             }
         }
         return message;
     }
     finally
     {
         EmsUtils.CloseMessageConsumer(consumer);
     }
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:44,代码来源:EmsTemplate.cs


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