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


C# QueueClient.Send方法代码示例

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


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

示例1: EnviarMensagem

        private static void EnviarMensagem()
        {
            queueClient = QueueClient.Create(QueueName);

            List<BrokeredMessage> listaMensagem =
                new List<BrokeredMessage>();

            listaMensagem.Add(CriarMensagemUnica("1", "Nota do Robson, 3.5"));
            listaMensagem.Add(CriarMensagemUnica("2", "Nota do Danilo, 4.0"));
            listaMensagem.Add(CriarMensagemUnica("3", "Nota do Vinicius, 1.2"));
            listaMensagem.Add(CriarMensagemUnica("4", "Nota do Sergio, 6.0"));
            listaMensagem.Add(CriarMensagemUnica("5", "Nota do Thiago, 2.0"));
            listaMensagem.Add(CriarMensagemUnica("6", "Nota do Marcelo, 8.5"));

            Console.WriteLine("\nEnviar mensagem para a Fila {0}", QueueName);
            foreach (BrokeredMessage message in listaMensagem)
            {
                while (true)
                {
                    try
                    {
                        queueClient.Send(message);
                    }
                    catch (MessagingException error)
                    {
                        if (!error.IsTransient)
                        {
                            Console.WriteLine(error.Message);
                        }
                        else
                        {
                            ManipularErros(error);
                        }
                    }
                    Console.WriteLine(
                        @"Mensagem enviar: {0}, {1}",
                        message.MessageId,
                        message.GetBody<string>());
                    break;
                }
            }
        }
开发者ID:lhlima,项目名称:CollaborationProjects,代码行数:42,代码来源:Program.cs

示例2: 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

示例3: SendMessages

        private static void SendMessages()
        {
            queueClient = QueueClient.Create(QueueName);

            List<BrokeredMessage> messageList = new List<BrokeredMessage>();

            messageList.Add(CreateSampleMessage("1", "First message information"));
            messageList.Add(CreateSampleMessage("2", "Second message information"));
            messageList.Add(CreateSampleMessage("3", "Third message information"));

            Console.WriteLine("\nSending messages to Queue...");

            foreach (BrokeredMessage message in messageList)
            {
                while (true)
                {
                    try
                    {
                        queueClient.Send(message);
                    }
                    catch (MessagingException e)
                    {
                        if (!e.IsTransient)
                        {
                            Console.WriteLine(e.Message);
                            throw;
                        }
                        else
                        {
                            HandleTransientErrors(e);
                        }
                    }
                    Console.WriteLine(string.Format("Message sent: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>()));
                    break;
                }
            }
        }
开发者ID:Eugene-Murray,项目名称:AzureServiceBusQueues,代码行数:37,代码来源:program.cs

示例4: Send

        void Send(TransportMessage message, QueueClient sender, Address address)
        {
            var numRetries = 0;
            var sent = false;

            while (!sent)
            {
                try
                {
                    using (var brokeredMessage = message.Body != null ? new BrokeredMessage(message.Body) : new BrokeredMessage())
                    {
                        brokeredMessage.CorrelationId = message.CorrelationId;
                        if (message.TimeToBeReceived < TimeSpan.MaxValue) brokeredMessage.TimeToLive = message.TimeToBeReceived;

                        foreach (var header in message.Headers)
                        {
                            brokeredMessage.Properties[header.Key] = header.Value;
                        }

                        brokeredMessage.Properties[Headers.MessageIntent] = message.MessageIntent.ToString();
                        brokeredMessage.MessageId = message.Id;
                        if (message.ReplyToAddress != null)
                        {
                            brokeredMessage.ReplyTo = message.ReplyToAddress.ToString();
                        }

                        sender.Send(brokeredMessage);
                        sent = true;
                    }
                }
                catch (MessagingEntityNotFoundException)
                {
                    throw new QueueNotFoundException { Queue = address };
                }
                // todo: outbox
                catch (MessagingEntityDisabledException)
                {
                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries * DefaultBackoffTimeInSeconds));
                }
                // back off when we're being throttled
                catch (ServerBusyException)
                {
                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries * DefaultBackoffTimeInSeconds));
                }
            }
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:54,代码来源:AzureServiceBusMessageQueueSender.cs

示例5: Main

        static void Main(string[] args)
        {
            try
            {

                //String serviceBusNamespace = "azuretest-ns";
                //String keyname = "RootManageSharedAccessKey";
                //String key = "3HzV1a5bcs/OOj0YS+Iec7XPA9ys2s9oqrUrg8pcILA=";

                //String connectionString = @"Endpoint=sb://" +
                //       serviceBusNamespace +
                //       @".servicebus.chinacloudapi.cn/;SharedAccessKeyName=" +
                //       keyname + @";SharedSecretValue=" + key;

                String connectionString = @"Endpoint=sb://azuretest-ns.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=3HzV1a5bcs/OOj0YS+Iec7XPA9ys2s9oqrUrg8pcILA=";

                int numCities = 10; // Use as the default, if no value is specified
                // at the command line.
                if (args.Count() != 0)
                {

                    if (args[0].ToLower().CompareTo("createqueue") == 0)
                    {
                        // No processing to occur other than creating the queue.
                        namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                        namespaceManager.CreateQueue(queueName);
                        Console.WriteLine("Queue named {0} was created.", queueName);
                        Environment.Exit(0);
                    }

                    if (args[0].ToLower().CompareTo("deletequeue") == 0)
                    {
                        // No processing to occur other than deleting the queue.
                        namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                        namespaceManager.DeleteQueue("TSPQueue");
                        Console.WriteLine("Queue named {0} was deleted.", queueName);
                        Environment.Exit(0);
                    }

                    // Neither creating or deleting a queue.
                    // Assume the value passed in is the number of cities to solve.
                    numCities = Convert.ToInt32(args[0]);
                }

                Console.WriteLine("Running for {0} cities.", numCities);

                queueClient = QueueClient.CreateFromConnectionString(connectionString, "TSPQueue");

                List<int> startCities = new List<int>();
                List<int> restCities = new List<int>();

                startCities.Add(0);
                for (int i = 1; i < numCities; i++)
                {
                    restCities.Add(i);
                }
                distances = new double[numCities, numCities];
                cityNames = new String[numCities];
                BuildDistances(@"c:\tsp\cities.txt", numCities);
                minDistance = -1;
                bestOrder = new int[numCities];
                permutation(startCities, 0, restCities);
                Console.WriteLine("Final solution found!");
                queueClient.Send(new BrokeredMessage("Complete"));

                queueClient.Close();
                Environment.Exit(0);

            }
            catch (ServerBusyException serverBusyException)
            {
                Console.WriteLine("ServerBusyException encountered");
                Console.WriteLine(serverBusyException.Message);
                Console.WriteLine(serverBusyException.StackTrace);
                Environment.Exit(-1);
            }
            catch (ServerErrorException serverErrorException)
            {
                Console.WriteLine("ServerErrorException encountered");
                Console.WriteLine(serverErrorException.Message);
                Console.WriteLine(serverErrorException.StackTrace);
                Environment.Exit(-1);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception encountered");
                Console.WriteLine(exception.Message);
                Console.WriteLine(exception.StackTrace);
                Environment.Exit(-1);
            }
        }
开发者ID:siszoey,项目名称:getPoisFromWeibo,代码行数:91,代码来源:Program.cs

示例6: SendListOfMessages

 //Enviar uma lista de mensagens para o cliente queue e imprimir as mensagens enviadas na consola
 static void SendListOfMessages(List<BrokeredMessage> list, QueueClient myQueueClient)
 {
     foreach (var message in list)
     {
         Console.Write(string.Format("Sending message with id: {0}", message.MessageId));
         myQueueClient.Send(message);
         Console.WriteLine("...sent");
     }
 }
开发者ID:sandrapatfer,项目名称:PROMPT11-10-CloudComputing.sandrapatfer,代码行数:10,代码来源:Program.cs

示例7: SendMessages

 private static void SendMessages(IEnumerable<ServiceBusEventMessage> messages, QueueClient queueClient)
 {
     foreach (var payLoad in messages)
     {
         var sendMessage = new BrokeredMessage(payLoad);
         queueClient.Send(sendMessage);
         System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("G") + "Sending Message " + payLoad);
     }
 }
开发者ID:has-taiar,项目名称:ServiceBusSample,代码行数:9,代码来源:Sender.cs

示例8: Send

        void Send(TransportMessage message, QueueClient sender, Address address)
        {
            var numRetries = 0;
            var sent = false;

            while (!sent)
            {
                try
                {
                    using (var brokeredMessage = message.Body != null ? new BrokeredMessage(message.Body) : new BrokeredMessage())
                    {
                        brokeredMessage.CorrelationId = message.CorrelationId;
                        if (message.TimeToBeReceived < TimeSpan.MaxValue) brokeredMessage.TimeToLive = message.TimeToBeReceived;

                        foreach (var header in message.Headers)
                        {
                            brokeredMessage.Properties[header.Key] = header.Value;
                        }

                        brokeredMessage.Properties[Headers.MessageIntent] = message.MessageIntent.ToString();
                        brokeredMessage.MessageId = message.Id;

                        if (message.ReplyToAddress != null)
                        {
                            brokeredMessage.ReplyTo = new DeterminesBestConnectionStringForAzureServiceBus().Determine(message.ReplyToAddress);
                        }

                        if (message.TimeToBeReceived < TimeSpan.MaxValue)
                        {
                            brokeredMessage.TimeToLive = message.TimeToBeReceived;
                        }

                        if (brokeredMessage.Size > 256*1024)
                        {
                            throw new MessageTooLargeException(string.Format("The message with id {0} is larger that the maximum message size allowed by Azure ServiceBus, consider using the databus instead", message.Id));
                        }

                        sender.Send(brokeredMessage);
                        sent = true;
                    }
                }
                catch (MessagingEntityNotFoundException)
                {
                    throw new QueueNotFoundException
                    {
                        Queue = address
                    };
                }
                    // todo: outbox
                catch (MessagingEntityDisabledException)
                {
                    logger.Warn(string.Format("Queue {0} is disable", sender.Path));

                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    logger.Warn("Will retry after backoff period");

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries*DefaultBackoffTimeInSeconds));
                }
                    // back off when we're being throttled
                catch (ServerBusyException ex)
                {
                    logger.Warn(string.Format("Server busy exception occured on queue {0}", sender.Path), ex);

                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    logger.Warn("Will retry after backoff period");

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries*DefaultBackoffTimeInSeconds));
                }
                    // connection lost
                catch (MessagingCommunicationException ex)
                {
                    logger.Warn(string.Format("Messaging Communication exception occured on queue {0}", sender.Path), ex);

                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    logger.Warn("Will retry after backoff period");

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries*DefaultBackoffTimeInSeconds));
                }
                    // took to long, maybe we lost connection
                catch (TimeoutException ex)
                {
                    logger.Warn(string.Format("Timeout exception occured on queue {0}", sender.Path), ex);

                    numRetries++;

                    if (numRetries >= MaxDeliveryCount) throw;

                    logger.Warn("Will retry after backoff period");

                    Thread.Sleep(TimeSpan.FromSeconds(numRetries*DefaultBackoffTimeInSeconds));
                }
//.........这里部分代码省略.........
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:101,代码来源:AzureServiceBusMessageQueueSender.cs


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