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


C# Queue.AsMessageQueue方法代码示例

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


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

示例1: DeleteMessage

 public virtual void DeleteMessage(Queue queue, string messageId)
 {
     using(var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
     {
         q.ReceiveById(messageId);
     }
 }
开发者ID:4lx,项目名称:Profiler,代码行数:7,代码来源:MSMQueueOperations.cs

示例2: CreateQueue

        public virtual Queue CreateQueue(Queue queue, bool transactional)
        {
            var path = queue.Address.ToShortFormatName();
            if(!QueueExists(queue)) //MessageQueue.Exist method does not accept format name
            {
                var q = MessageQueue.Create(path, transactional);
                return _mapper.MapQueue(q);
            }

            return _mapper.MapQueue(queue.AsMessageQueue());
        }
开发者ID:nanohex,项目名称:ServiceInsight,代码行数:11,代码来源:MSMQueueOperations.cs

示例3: DeleteMessage

 public void DeleteMessage(Queue queue, string messageId)
 {
     try
     {
         using(var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
         {
             q.ReceiveById(messageId);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("Could not delete message {0} to queue {1}", messageId, queue), ex);
         throw;
     }
 }
开发者ID:NicoVermeir,项目名称:ServiceInsight,代码行数:15,代码来源:MSMQueueOperations.cs

示例4: GetMessageBody

        public MessageBody GetMessageBody(Queue queue, string messageId)
        {
            using (var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
            {
                q.MessageReadPropertyFilter.SetAll();
                q.MessageReadPropertyFilter.SourceMachine = true;

                try
                {
                    return _mapper.MapBody(q.PeekById(messageId));
                }
                catch (InvalidOperationException) //message is removed from the queue (by another process)
                {
                    return null;
                }
            }
        }
开发者ID:4lx,项目名称:Profiler,代码行数:17,代码来源:MSMQueueOperations.cs

示例5: GetMessages

        public virtual IList<MessageInfo> GetMessages(Queue queue)
        {
            using (var q = queue.AsMessageQueue())
            {
                q.MessageReadPropertyFilter.ClearAll();
                q.MessageReadPropertyFilter.Id = true;
                q.MessageReadPropertyFilter.Label = true;
                q.MessageReadPropertyFilter.SentTime = true;

                var result = new List<MessageInfo>();
                if (!queue.CanRead)
                {
                    return result;
                }

                var msgLoop = q.GetMessageEnumerator2();
                try
                {
                    while (msgLoop.MoveNext())
                    {
                        try
                        {
                            var currentMessage = msgLoop.Current;
                            if (currentMessage != null)
                            {
                                result.Add(_mapper.MapInfo(currentMessage));
                            }
                        }
                        catch (MessageQueueException ex)
                        {
                            Logger.Error("There was an error reading message from the queue.", ex);
                        }
                    }
                }
                finally
                {
                    msgLoop.Close();
                }

                return result;
            }
        }
开发者ID:roycornelissen,项目名称:ServiceInsight,代码行数:42,代码来源:MSMQueueOperations.cs

示例6: GetMessageBody

        public MessageBody GetMessageBody(Queue queue, string messageId)
        {
            try
            {
                using (var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
                {
                    q.MessageReadPropertyFilter.SetAll();
                    q.MessageReadPropertyFilter.SourceMachine = true;

                    return _mapper.MapBody(q.PeekById(messageId));
                }
            }
            catch (InvalidOperationException) //message is removed from the queue (by another process)
            {
                return null;
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Could not read message {0} body.", messageId), ex);
                throw;
            }
        }
开发者ID:NicoVermeir,项目名称:ServiceInsight,代码行数:22,代码来源:MSMQueueOperations.cs

示例7: GetMessageCount

        public virtual int GetMessageCount(Queue queue)
        {
            var messageCount = 0;

            using (var q = queue.AsMessageQueue())
            {
                q.MessageReadPropertyFilter.ClearAll();
                var msgLoop = q.GetMessageEnumerator2();

                if (queue.CanRead)
                {
                    while (msgLoop.MoveNext())
                    {
                        messageCount++;
                    }
                }
            }
            return messageCount;
        }
开发者ID:4lx,项目名称:Profiler,代码行数:19,代码来源:MSMQueueOperations.cs

示例8: Send

 public virtual void Send(Queue queue, object message)
 {
     using(var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
     {
         q.Send(message, MessageQueueTransactionType.Single);
     }
 }
开发者ID:4lx,项目名称:Profiler,代码行数:7,代码来源:MSMQueueOperations.cs

示例9: PurgeQueue

 public virtual void PurgeQueue(Queue queue)
 {
     using(var q = queue.AsMessageQueue(QueueAccessMode.ReceiveAndAdmin))
     {
         q.Purge();
     }
 }
开发者ID:4lx,项目名称:Profiler,代码行数:7,代码来源:MSMQueueOperations.cs

示例10: MoveMessage

        public virtual void MoveMessage(Queue source, Queue destination, string messageId)
        {
            using(var tx = new TransactionScope())
            using(var queueDest = destination.AsMessageQueue(QueueAccessMode.SendAndReceive))
            using(var queueSource = source.AsMessageQueue(QueueAccessMode.SendAndReceive))
            {
                Guard.True(queueSource.CanRead, () => new QueueManagerException(string.Format("Can not read messages from queue {0}", source.Address)));
                Guard.True(queueSource.Transactional, () => new QueueManagerException(string.Format("Queue {0} is not transactional", source.Address)));

                Guard.True(queueDest.CanRead, () => new QueueManagerException(string.Format("Can not read messages from queue {0}", destination.Address)));
                Guard.True(queueDest.Transactional, () => new QueueManagerException(string.Format("Queue {0} is not transactional", destination.Address)));

                Func<string, Message> retreival = x => queueSource.ReceiveById(x, MessageQueueTransactionType.Automatic);

                var msg = retreival.TryGetValue(messageId);

                Guard.NotNull(() => msg, msg, () => new QueueManagerException("Message could not be loaded."));

                queueDest.Send(msg, MessageQueueTransactionType.Automatic);

                tx.Complete();
            }
        }
开发者ID:4lx,项目名称:Profiler,代码行数:23,代码来源:MSMQueueOperations.cs

示例11: MoveMessage

        public virtual void MoveMessage(Queue source, Queue destination, string messageId)
        {
            using(var tx = new TransactionScope())
            using(var queueDest = destination.AsMessageQueue(QueueAccessMode.SendAndReceive))
            using(var queueSource = source.AsMessageQueue(QueueAccessMode.SendAndReceive))
            {
                Guard.True(queueSource.CanRead, () => new QueueManagerException(string.Format("Can not read messages from queue {0}", source.Address)));
                Guard.True(queueSource.Transactional, () => new QueueManagerException(string.Format("Queue {0} is not transactional", source.Address)));

                Guard.True(queueDest.CanRead, () => new QueueManagerException(string.Format("Can not read messages from queue {0}", destination.Address)));
                Guard.True(queueDest.Transactional, () => new QueueManagerException(string.Format("Queue {0} is not transactional", destination.Address)));

                Message msg = null;

                try
                {
                    queueSource.MessageReadPropertyFilter.SetAll();
                    msg = queueSource.ReceiveById(messageId, MessageQueueTransactionType.Automatic);
                }
                catch
                {
                }

                Guard.NotNull(() => msg, msg, () => new QueueManagerException("Message could not be loaded."));

                queueDest.Send(msg, MessageQueueTransactionType.Automatic);

                tx.Complete();
            }
        }
开发者ID:nanohex,项目名称:ServiceInsight,代码行数:30,代码来源:MSMQueueOperations.cs

示例12: Send

 public void Send(Queue queue, object message)
 {
     try
     {
         using(var q = queue.AsMessageQueue(QueueAccessMode.SendAndReceive))
         {
             q.Send(message, MessageQueueTransactionType.Single);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("Could not send a message to queue {0}", queue), ex);
         throw;
     }
 }
开发者ID:NicoVermeir,项目名称:ServiceInsight,代码行数:15,代码来源:MSMQueueOperations.cs

示例13: PurgeQueue

 public void PurgeQueue(Queue queue)
 {
     try
     {
         using(var q = queue.AsMessageQueue(QueueAccessMode.ReceiveAndAdmin))
         {
             q.Purge();
         }
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("Could not purge queue {0}", queue), ex);
         throw;
     }
 }
开发者ID:NicoVermeir,项目名称:ServiceInsight,代码行数:15,代码来源:MSMQueueOperations.cs

示例14: GetMessageCount

        public int GetMessageCount(Queue queue)
        {
            var messageCount = 0;

            try
            {
                using (var q = queue.AsMessageQueue())
                {
                    q.MessageReadPropertyFilter.ClearAll();
                    var msgLoop = q.GetMessageEnumerator2();

                    if (queue.CanRead)
                    {
                        while (msgLoop.MoveNext())
                        {
                            messageCount++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Could not retrieve message count from queue {0}", queue), ex);
                throw;
            }
            return messageCount;
        }
开发者ID:NicoVermeir,项目名称:ServiceInsight,代码行数:27,代码来源:MSMQueueOperations.cs


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