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


C# MessageQueue.Peek方法代码示例

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


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

示例1: When_a_failed_message_arrives_to_error_queue_will_have_another_message_explaining_what_happened

        public void When_a_failed_message_arrives_to_error_queue_will_have_another_message_explaining_what_happened()
        {
            int count = 0;
            Transport.MessageArrived += o =>
            {
                Interlocked.Increment(ref count);
                throw new InvalidOperationException("Operation is not valid due to the current state of the object.");
            };

            Transport.Send(TestQueueUri, new object[] { DateTime.Today });

            using (var errorQueue = new MessageQueue(testQueuePath + ";errors"))
            {
                errorQueue.Formatter = new XmlMessageFormatter(new[] { typeof(string) });
                errorQueue.MessageReadPropertyFilter.SetAll();
                errorQueue.Peek(TimeSpan.FromSeconds(30));//for debugging

                var messageCausingError = errorQueue.Receive(TimeSpan.FromSeconds(30));
                Assert.NotNull(messageCausingError);
                errorQueue.Peek(TimeSpan.FromSeconds(30));//for debugging
                var messageErrorDescription = errorQueue.Receive(TimeSpan.FromSeconds(30));
                var error = (string)messageErrorDescription.Body;
                Assert.Contains(
                    "System.InvalidOperationException: Operation is not valid due to the current state of the object.",
                    error);

                Assert.Equal(
                    messageCausingError.Id,
                    messageErrorDescription.CorrelationId);
            }
        }
开发者ID:BiYiTuan,项目名称:rhino-esb,代码行数:31,代码来源:FailureToProcessMessage.cs

示例2: getFirstReservation

 public Message getFirstReservation()
 {
     MessageQueue queue = new MessageQueue(FlyHotelConstant.ADRESSE_QUEUE);
     queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(DemandeReservation) });
     Message messageResa = queue.Peek();
     return messageResa;
 }
开发者ID:math-th,项目名称:net-resa-tp,代码行数:7,代码来源:clsMsmq.cs

示例3: Moving_to_errors_queue_directly_move_message_to_errors

		public void Moving_to_errors_queue_directly_move_message_to_errors()
		{
			var queueStrategy = new FlatQueueStrategy(new EndpointRouter(), testQueueEndPoint.Uri);
			openedQueue.Send(new Message(new TestMessage { Name = "ayende" }));
			Message msg = openedQueue.Receive();
			queueStrategy.SendToErrorQueue(openedQueue, msg);

			using(var errQueue = new MessageQueue(testQueuePath +"#errors"))
			{
				var message = errQueue.Peek(TimeSpan.FromMilliseconds(250));
				Assert.NotNull(message);
			}
		}
开发者ID:JackWangCUMT,项目名称:rhino-esb,代码行数:13,代码来源:FlatQueueStrategyTests.cs

示例4: btnLire_Click

        private void btnLire_Click(object sender, EventArgs e)
        {
            MessageQueue mqVols = new MessageQueue(@".\private$\cmdvols");
            MessageQueue mqHotels = new MessageQueue(@".\private$\cmdhotels");
            mqVols.Formatter = new XmlMessageFormatter(new Type[] { typeof(clsVolEntity) });
            mqHotels.Formatter = new XmlMessageFormatter(new Type[] { typeof(clsHotelEntity) });
            var messageVol = (clsVolEntity)mqVols.Peek().Body;
            var messageHotel = (clsHotelEntity)mqHotels.Peek().Body;

            clsVolEntity vol = new clsVolEntity();
            vol.dateDepart = messageVol.dateDepart;
            vol.villeDepart = messageVol.villeDepart;
            vol.paysDepart = messageVol.paysDepart;
            vol.villeDestination = messageVol.villeDestination;
            vol.paysDestination = messageVol.paysDestination;
            vol.prixVol = messageVol.prixVol;
            vol.infoClient = messageVol.infoClient;

            clsHotelEntity hotel = new clsHotelEntity();
            hotel.nomHotel = messageHotel.nomHotel;
            hotel.adresseHotel = messageHotel.adresseHotel;
            hotel.cpHotel = messageHotel.cpHotel;
            hotel.villeHotel = messageHotel.villeHotel;
            hotel.paysHotel = messageHotel.paysHotel;
            hotel.dateArrivee = messageHotel.dateArrivee;
            hotel.duree = messageHotel.duree;
            hotel.infoClient = messageHotel.infoClient;

            clsInfoClient client = vol.infoClient;

            // Enregistrement en mode transactionnel
            bool resEnregistrement = new TraitementCommandeLibrary.libTraitementCommande().ajouterCommande(hotel, vol, client);

            // Transaction OK
            if (resEnregistrement == true)
            {
                txtListe.AppendText("Enregistrement du vol " + vol.villeDepart + " - " + vol.villeDestination + " et l'hotel " + hotel.nomHotel);
                mqVols.Receive();
                mqHotels.Receive();
            }
            // Transaction KO
            else
            {
                txtListe.AppendText("Impossible d'enregsitrer le vol " + vol.villeDepart + " - " + vol.villeDestination + " et l'hotel " + hotel.nomHotel);
            }
            mqVols.Close();
            mqHotels.Close();
        }
开发者ID:Clemzd,项目名称:ProjetVacances,代码行数:48,代码来源:Form1.cs

示例5: PeekWithoutTimeout

 private static Message PeekWithoutTimeout(MessageQueue q, Cursor cursor, PeekAction action)
 {
     Message ret = null;
     try
     {
         ret = q.Peek(new TimeSpan(1), cursor, action);
     }
     catch (MessageQueueException mqe)
     {
         if (!mqe.Message.ToLower().Contains("timeout"))
         {
             throw;
         }
     }
     return ret;
 }
开发者ID:trasa,项目名称:TwitDegrees,代码行数:16,代码来源:Program.cs

示例6: IsQueueEmpty

 /// <summary>
 /// 	Checks for one second to ensure the queue is empty
 /// </summary>
 public static bool IsQueueEmpty(string queuePath)
 {
     try
     {
         var queue = new MessageQueue(queuePath, QueueAccessMode.Peek);
         queue.Peek(TimeSpan.FromSeconds(1));
     }
     catch (MessageQueueException exception)
     {
         if (exception.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
         {
             return true;
         }
         throw;
     }
     return false;
 }
开发者ID:phoenixwebgroup,项目名称:DotNetExtensions,代码行数:20,代码来源:MsmqHelper.cs

示例7: When_a_message_fails_enough_times_it_is_moved_to_error_queue_using_non_transactional_queue

        public void When_a_message_fails_enough_times_it_is_moved_to_error_queue_using_non_transactional_queue()
        {
            int count = 0;
            Transport.MessageArrived += o =>
            {
                Interlocked.Increment(ref count);
                throw new InvalidOperationException();
            };

            Transport.Send(TestQueueUri, new object[] { DateTime.Today });

            using (var errorQueue = new MessageQueue(testQueuePath + ";errors"))
            {
                Assert.NotNull(errorQueue.Peek());
                Assert.Equal(5, count);
            }
        }
开发者ID:BiYiTuan,项目名称:rhino-esb,代码行数:17,代码来源:FailureToProcessMessage.cs

示例8: Pick_From_NServiceBus_Msmq

        public static void Pick_From_NServiceBus_Msmq()
        {
            var address = Address.Parse("[email protected]cal");
            address = Address.Parse("MessageMonitorAudit");
            var path = NServiceBus.Utils.MsmqUtilities.GetFullPath(address);
            using (var queue = new MessageQueue(path, QueueAccessMode.PeekAndAdmin))
            {
                var mpf = new MessagePropertyFilter();
                mpf.SetAll();
                queue.MessageReadPropertyFilter = mpf;

                var msg = queue.Peek(TimeSpan.FromMinutes(1));

                var tm = NServiceBus.Utils.MsmqUtilities.Convert(msg);

                if(tm.Is_Failed_Message())
                    tm.To_NServiceBus_Failed_Message();
            }
        }
开发者ID:valeriob,项目名称:MessageMonitor,代码行数:19,代码来源:NServiceBus_Queue_Listener.cs

示例9: btnRead_Click

        private void btnRead_Click(object sender, EventArgs e)
        {
            MessageQueue MyMQ = new MessageQueue(@".\private$\BankENSEIRB");
            MyMQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(TransfertInfo) });

            var message = (TransfertInfo)MyMQ.Peek().Body;

            bool ResT = Transfert(message.BO, message.BD, message.CC, message.CD, message.Montant);

            if (ResT == true)
            {
                MyMQ.Receive();
                MyMQ.r
            }
            else
            {
            }
            MyMQ.Close();
        }
开发者ID:math-th,项目名称:net-resa-tp,代码行数:19,代码来源:Form1.cs

示例10: ReceiveMessage

        //Receive message from CallDispositionQueue
        public string ReceiveMessage()
        {
            bool valid_Message = false;
            string returnMessageId = null;
            Message message = new Message();
            
            //connect to the queue on the local path
            MessageQueue myQueue = new MessageQueue(@".\Private$\CallDispositionQueue");
            myQueue.MessageReadPropertyFilter.CorrelationId = true;

            //TODO: Message process to Cubs/set a connection.

            try
            {
                myQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(MSMQ.Contracts.CallDisposition) });
                message = myQueue.Peek(TimeSpan.FromSeconds(10.0));
                CallDisposition cd = (CallDisposition)message.Body;

                if (message.Body == (CallDisposition)message.Body)
                {
                    message = myQueue.Receive(TimeSpan.FromSeconds(10.0));
                    Console.WriteLine("Message Received.");
                    valid_Message = true;

                    _id = cd.DispositionId;
                    Console.WriteLine("Disposition ID is: {0}", _id);
                    Console.WriteLine("CubsActNum  is: {0}", cd.CubsActNum);
                    Console.WriteLine("PhoneNumber is: {0}", cd.PhoneNumber);
                    Console.WriteLine("CallDateStr is: {0}", cd.CallDateStr);
                    Console.WriteLine("CallStartStr is: {0}", cd.CallStartStr);
                    Console.WriteLine("Agent Initials is: {0}", cd.Initials);
                    Console.WriteLine("Logon is: {0}", cd.Logon);
                    Console.WriteLine("CampaignType is: {0}", cd.CampaignType);
                    Console.WriteLine("Action Code is: {0}", cd.ActionCode);
                }

                returnMessageId = message.Id;
            }
            catch (MessageQueueException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("There is no messages in the queue right now");
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (NullReferenceException nx)
            {
                Console.WriteLine(nx.Message);
            }
            
            if (valid_Message)
            {
                //update the row in the database when the message is valid. 
                const string query = "DECLARE @TimeStamp DATETIME = GETDATE();" +
                                        "UPDATE [CallLogs].[DialConnect].[CallDispositions] " +
                                        "SET [SentToCubsDT] = @TimeStamp" + " " +
                                        "WHERE [Id] = @DispositionId";

                using (SqlConnection conn = new SqlConnection("Data Source=stlbisql-t01;Initial Catalog=CallLogs;Integrated Security=True"))
                {
                    var sqlcmd = new SqlCommand(query, conn);
                    sqlcmd.Parameters.Add("@DispositionId", SqlDbType.Int);
                    sqlcmd.Parameters["@DispositionId"].Value = _id;

                    try
                    {
                        conn.Open();
                        sqlcmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine("Message Failed to update the SentToCubsDT");
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            else
            {
                Console.WriteLine("Message Failed to Process");
                PoisonMessage ps = new PoisonMessage();                
                ps.SentToPoisonMessage(message);
            }
            
            return returnMessageId;
        }
开发者ID:adhikaribipin,项目名称:MSMQTesting,代码行数:92,代码来源:ProcessMessageToCubs.cs

示例11: Peeking_twice_different_queue_isntances_on_same_queue

        public void Peeking_twice_different_queue_isntances_on_same_queue()
        {
            queue.Send("a");

            var peek1 = queue.Peek();

            using(var q2 = new MessageQueue(testQueuePath,QueueAccessMode.Receive))
            {
                var peek2 = q2.Peek();
                Assert.Equal(peek1.Id, peek2.Id);
            }
        }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:12,代码来源:MsmqTests.cs

示例12: Competing_consumers

        public void Competing_consumers()
        {
            queue.Send("a");

            var peek1 = queue.Peek();

            using (var q2 = new MessageQueue(testQueuePath, QueueAccessMode.Receive))
            {
                var peek2 = q2.Peek();
                q2.ReceiveById(peek2.Id);
            }

            Assert.Throws<InvalidOperationException>(()=>queue.ReceiveById(peek1.Id))
            ;
        }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:15,代码来源:MsmqTests.cs

示例13: PeekMessage

 private Message PeekMessage(MessageQueue queue, Cursor cursor, PeekAction action)
 {
     try
     {
         return queue.Peek(_timeout, cursor, action);
     }
     catch
     {
         return null;
     }
 }
开发者ID:jessezhao,项目名称:shuttle-esb,代码行数:11,代码来源:MsmqQueue.cs

示例14: MailServer

 private void MailServer(object sender, ElapsedEventArgs e)
 {
     try
     {
         bool fileSuccesfullSended = false;
         //Открываем очередь по пути queuePath
         using (var ServiceQueue = new MessageQueue(queuePath))
         {
             //Задаем сериализацию
             ServiceQueue.Formatter = new XmlMessageFormatter(
                 new String[] { "System.String" });
             //Проверяем, пустая ли очередь
             if (ServiceQueue.GetAllMessages().Length > 0)
             {
                 //Получаем сообщение из очереди, при этом оно удаляется
                 var queueMessage = ServiceQueue.Peek();
                 //Создаем email сообщение
                 var mail = new MailMessage(from, toMessage, queueMessage.Label, queueMessage.Body as string);
                 //Создаем smtp подключение
                 try
                 {
                     var client = smtpClient.StartConnection();
                     client.Send(mail);
                     //Отмечаем, что файл успешно отправлен
                     fileSuccesfullSended = true;
                 }
                 catch (SmtpException)
                 {
                     //Пытаемся переподключиться
                     try
                     {
                         smtpClient.Reconnect();
                         var client = smtpClient.StartConnection();
                         client.Send(mail);
                         //Отмечаем, что файл успешно отправлен
                         fileSuccesfullSended = true;
                     }
                     catch
                     {
                         fileSuccesfullSended = false;
                     }
                 }
                 catch (InvalidOperationException)
                 {
                     //Пытаемся переподключиться
                     try
                     {
                         smtpClient.Reconnect();
                         var client = smtpClient.StartConnection();
                         client.Send(mail);
                         //Отмечаем, что файл успешно отправлен
                         fileSuccesfullSended = true;
                     }
                     catch
                     {
                         fileSuccesfullSended = false;
                     }
                 }
                 //Удаляем только что отосланное, если оно успешно отправлено
                 if (fileSuccesfullSended)
                     ServiceQueue.Receive();
             }
         }
     }
     catch
     {
         return;
     }
 }
开发者ID:TitovSP,项目名称:ExceptionService,代码行数:69,代码来源:Service1.cs

示例15: PeekMessage

        private Message PeekMessage(MessageQueue queue, Cursor cursor, PeekAction action)
        {
            ResetUnderlyingMessageData();

            try
            {
                underlyingMessageData = queue.Peek(timeout, cursor, action);

                return (Message)underlyingMessageData;
            }
            catch
            {
                return null;
            }
        }
开发者ID:nnyamhon,项目名称:shuttle-esb,代码行数:15,代码来源:MsmqQueue.cs


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