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


C# QueueClient.Receive方法代码示例

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


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

示例1: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     lstMensagens.Items.Add("status: Recebendo mensagens...");
     this.Refresh();
     queueClient = QueueClient.Create(QueueName);
     BrokeredMessage message = null;
     while (true)
     {
         try
         {
             message = queueClient.Receive(TimeSpan.FromSeconds(2));
             if (message != null)
             {
                 lstResultado.Items.Add(string.Format("Id: {0}, Body: {1}", message.MessageId, message.GetBody<string>()));
                 message.Complete();
             }
             else break;
         }
         catch (MessagingException error)
         {
             if (!error.IsTransient)
             {
                 lstMensagens.Items.Add("status: " + error.Message);
             }
             else ManipularExcecoes(error);
         }
     }
     queueClient.Close();
 }
开发者ID:lhlima,项目名称:CollaborationProjects,代码行数:29,代码来源:FormMensagem.cs

示例2: ReceivedMessage

        public string ReceivedMessage()
        {
            var factory = MessagingFactory.CreateFromConnectionString(ConnectionString);
            _client = factory.CreateQueueClient(ServiceProperties.QueueName);

            var message = _client.Receive();

            return message.GetBody<string>();
        }
开发者ID:malindasuhash,项目名称:WindowsServiceBusExample-SendReceive,代码行数:9,代码来源:MessageReceiver.cs

示例3: ReceiveNMessagesFromQueue

 //Recebe messageCount mensagens da queue, com timeout de 5 segundos por mensagem.
 //Imprimir na consola o id e o body de cada mensagem
 static void ReceiveNMessagesFromQueue(QueueClient myQueueClient, long messageCount)
 {
     for (int i = 0; i < messageCount; i++)
     {
         var message = myQueueClient.Receive(new TimeSpan(0, 0, 5));
         if (message != null)
         {
             Console.WriteLine("Message received. Id: {0} Body: {1}", message.MessageId, message.GetBody<string>());
         }
     }
 }
开发者ID:sandrapatfer,项目名称:PROMPT11-10-CloudComputing.sandrapatfer,代码行数:13,代码来源:Program.cs

示例4: ReturnMessageToSourceQueue

    /// <summary>
    ///     May throw a timeout exception if a message with the given id cannot be found.
    /// </summary>
    /// <param name="seqNumber"></param>
    public void ReturnMessageToSourceQueue(QueueClient queue, QueueClient deadLetterQueue, ServiceBusMQ.Model.QueueItem itm) {
      //var rec = MessagingFactory.Create()
      //rec.
      
      BrokeredMessage message;
      try {
        
        message = deadLetterQueue.Receive((long)itm.MessageQueueItemId);
      } catch(Exception e) { 
      
        message = queue.Receive((long)itm.MessageQueueItemId);
      }

        //message.Abandon();
        queue.Send(message.Clone());


      //} catch( Exception ex ) {
      //  TryFindMessage(itm);
      //}
    }
开发者ID:do0g,项目名称:ServiceBusMQManager,代码行数:25,代码来源:ErrorManager.cs

示例5: Main

 static void Main(string[] args)
 {
     CreateQueue();
     queueClient = QueueClient.Create(queueName, ReceiveMode.PeekLock);
     Console.Out.WriteLine("Queue client receive mode is " + queueClient.Mode.ToString());
     try
     {
         while (true)
         {
             long msgCount = nsMgr.GetQueue(queueName).MessageCountDetails.ActiveMessageCount;
             Console.Out.WriteLine("Ready for messages... ");
             if (msgCount > 0) { Console.Out.WriteLine("The queue has " + msgCount + " messages waiting"); }
             var msg = queueClient.Receive(new TimeSpan(1, 0, 0));
             Console.Out.WriteLine("Received message with id {0}", msg.MessageId);
             Messages.Greeting greeting = msg.GetBody<Messages.Greeting>();
             Console.Out.WriteLine("Message for: {0}", greeting.Name );
             Console.Out.WriteLine("{0}\n", greeting.Message);
             if (queueClient.Mode == ReceiveMode.PeekLock)
             {
                 try
                 {
                     Console.Out.WriteLine("Completing message with lock token {0}", msg.LockToken);
                     queueClient.Complete(msg.LockToken);
                 }
                 catch (MessageLockLostException)
                 {
                     Console.Out.WriteLine("Oh noes! We lost the lock on the message. ");
                 }
             }
             Console.Out.WriteLine();
         }
     }
     finally
     {
         queueClient.Close();
     }
 }
开发者ID:kennethahn,项目名称:ServiceBusRelayDemo,代码行数:37,代码来源:Consumer.cs

示例6: ReturnMessageToSourceQueue

        /// <summary>
        ///     May throw a timeout exception if a message with the given id cannot be found.
        /// </summary>
        /// <param name="seqNumber"></param>
        public void ReturnMessageToSourceQueue(QueueClient queue, QueueClient deadLetterQueue, ServiceBusMQ.Model.QueueItem itm)
        {
            try {
            var message = deadLetterQueue.Receive((long)itm.MessageQueueItemId);

            message.Abandon();
            //queue.Send(message.Clone());

              } catch( Exception ex ) {
            TryFindMessage(itm);
              }
        }
开发者ID:jjchiw,项目名称:ServiceBusMQManager,代码行数:16,代码来源:ErrorManager.cs

示例7: Receive

        //TODO: move to ServivceBus class
        public static void Receive(QueueClient client)
        {
            try
            {
                Trace.TraceInformation("1. Pull messages off of queue");
                client.Receive();
            }

            catch (Exception ex)
            {

                Trace.TraceError("On retrieving message from queue. Client.Receive() before while loop starts. " + ex.Message);
            }

            bool messageFound = true;
            BrokeredMessage message = null;

            // Continuously process messages on the queue
            while (messageFound)
            {

                try
                {
                    Trace.TraceInformation("2. Pull messages off of queue");
                    message = client.Receive();
                }

                catch (Exception ex)
                {

                    Trace.TraceError("On retrieving message from queue. Client.Receive() inside while loop. " + ex.Message);
                }

                DateTime? dateCreated = null;
                var region = string.Empty;
                var messageId = string.Empty;

                if (message != null)
                {
                    try
                    {
                        //Trace.TraceInformation("Body: " + message.GetBody<string>());
                        //Trace.TraceInformation("MessageID: " + message.MessageId);

                        //Trace.TraceInformation("Region Code: " +
                        //                       message.Properties["RegionCode"]);
                        //Trace.TraceInformation("Date Created: " +
                        //                       message.Properties["DateCreated"]);

                        dateCreated = Convert.ToDateTime(message.Properties["DateCreated"]);
                        region = message.Properties["RegionCode"].ToString();
                        messageId = message.MessageId;
                    }
                    catch (Exception ex)
                    {
                        // Indicate a problem, unlock message in queue
                        message.Abandon();
                        Trace.TraceError("On CreateAndSendMessage: " + ex.Message);
                    }

                    // Remove message from queue

                    if (dateCreated == null || region == string.Empty)
                    {
                        message.Abandon();
                        Trace.TraceWarning("Message abandoned: where date created is " + dateCreated + " and where region is " + region);
                        continue;
                    }

                    Trace.TraceInformation("3. Message Found");
                    message.Complete();
                    Trace.TraceInformation("4. Message marked as complete. Reading from Azure table storage is next...");

                    var dataSourceAzureTable = new DataSource.AzureTable();

                    dataSourceAzureTable.GetRows(messageId,region, dateCreated);

                }
                else
                {
                    Trace.TraceInformation("2.5 No message found on queue and no error reported.");
                    messageFound = false;

                }
            }
        }
开发者ID:richstep,项目名称:ExportAzureTableStorageToSqlServer,代码行数:87,代码来源:MessageAction.cs

示例8: Main

        static void Main(string[] args)
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            if(args.Length > 0)
            {
                PrintUsage();
            }

            if(!Directory.Exists(s_DownloadRootFolder))
            {
                Directory.CreateDirectory(s_DownloadRootFolder);
            }

            //Get Service Bus
            var queueConnectionString =
                CloudConfigurationManager.GetSetting("Uploader.ServiceBus.ConnectionString");
            var queueName = CloudConfigurationManager.GetSetting("Uploader.UploadQueueName");
            s_QueueClient = QueueClient.CreateFromConnectionString(queueConnectionString, queueName, ReceiveMode.ReceiveAndDelete);

            CloudBlobClient blobClient = s_Account.CreateCloudBlobClient();

            while (true)
            {
                try
                {
                    var message = s_QueueClient.Receive();

                    //no new messages go back and wait again for more
                    if(message == null)
                    {
                        continue;
                    }

                    FileUploadedMessage etlUploadedMessage = JsonConvert.DeserializeObject<FileUploadedMessage>(message.GetBody<string>());

                    Console.WriteLine("Got uploaded file notification for " + etlUploadedMessage.FileName);

                    // Retrieve a reference to a container.
                    CloudBlobContainer container = blobClient.GetContainerReference(etlUploadedMessage.ContainerName.ToLower());

                    var blockBlob = container.GetBlockBlobReference(etlUploadedMessage.FileName);
                    var localFilePath = Path.Combine(s_DownloadRootFolder, etlUploadedMessage.ContainerName.ToLower());
                    var filePath = etlUploadedMessage.FileName.Replace("/", "\\");
                    localFilePath = Path.Combine(localFilePath, filePath);

                    if (!Directory.Exists(Path.GetDirectoryName(localFilePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(localFilePath));
                    }

                    if (File.Exists(localFilePath))
                    {
                        File.Delete(localFilePath);
                    }

                    //Get the file
                    using (Stream cloudStoredBits = blockBlob.OpenRead())
                    using (FileStream fs = new FileStream(localFilePath, FileMode.CreateNew, FileAccess.ReadWrite))
                    {
                        Console.WriteLine("Downloading Cloud file [" + etlUploadedMessage.ContainerName + "]" + etlUploadedMessage.FileName
                            + " to " + localFilePath);
                        cloudStoredBits.CopyTo(fs);
                    }

                    //Delete it from blob storage. Cloud storage isn't cheap :-)
                    Console.WriteLine("Deleting Cloud file [" + etlUploadedMessage.ContainerName + "]" + etlUploadedMessage.FileName);
                    blockBlob.Delete(DeleteSnapshotsOption.IncludeSnapshots);
                }
                catch(Exception e)
                {
                    Console.WriteLine("Unexpected Exception occured. See this exception - " + e);
                }
            }
        }
开发者ID:sedouard,项目名称:UploadAnywhere,代码行数:75,代码来源:Program.cs


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