示例#1
0
        static void Main(string[] args)
        {
            GetUserCredentials();
            MessagingFactory factory = null;

            try
            {
                //*****************************************************************************************************
                //                                   Management Operations
                //*****************************************************************************************************
                NamespaceManager namespaceClient = NamespaceManager.CreateFromConnectionString(ServiceBusConnectionString);

                Console.WriteLine("\nCreating Queue '{0}'...", QueueName);

                // Delete if exists
                if (namespaceClient.QueueExists(AsyncSender.QueueName))
                {
                    namespaceClient.DeleteQueue(AsyncSender.QueueName);
                }

                namespaceClient.CreateQueue(QueueName);

                //*****************************************************************************************************
                //                                   Runtime Operations
                //*****************************************************************************************************
                factory = MessagingFactory.CreateFromConnectionString(ServiceBusConnectionString);

                QueueClient myQueueClient = factory.CreateQueueClient(AsyncSender.QueueName);

                //*****************************************************************************************************
                //                                   Sending messages to a Queue
                //*****************************************************************************************************
                List <BrokeredMessage> messageList = new List <BrokeredMessage>();

                messageList.Add(CreateIssueMessage("1", "First Package"));
                messageList.Add(CreateIssueMessage("2", "Second Package"));
                messageList.Add(CreateIssueMessage("3", "Third Package"));

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

                foreach (BrokeredMessage message in messageList)
                {
                    // Initiate the asynchronous send
                    myQueueClient.BeginSend(message, OnSendComplete, new Tuple <QueueClient, string>(myQueueClient, message.MessageId));
                    Console.WriteLine(string.Format("Asynchronous Message Send Begin: Id = {0}, Body = {1}", message.MessageId, message.GetBody <string>()));
                }

                Console.WriteLine("\nAfter all messages are sent, press ENTER to clean up and exit.\n");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception {0}", e.ToString());
                throw;
            }
            finally
            {
                // Closing factory close all entities created from the factory.
                if (factory != null)
                {
                    factory.Close();
                }
            }
        }
 public IAsyncResult BeginSend(BrokeredMessage message, AsyncCallback callback, object state)
 {
     return(_queueClient != null
                         ? _queueClient.BeginSend(message, callback, state)
                         : _sender.BeginSend(message, callback, state));
 }
示例#3
0
 public void SendAsync(BrokeredMessage message)
 {
     queueClient.BeginSend(message, x => ProcessEndSend(x, message), queueClient);
 }