Exemple #1
0
        public void DequeueAndUpdate()
        {
            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Get a reference to a queue named "sample-queue" and then create it
            QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue"));

            queue.Create();
            try
            {
                // Add several messages to the queue
                queue.EnqueueMessage("first");
                queue.EnqueueMessage("second");
                queue.EnqueueMessage("third");

                // Get the messages from the queue with a short visibility timeout
                List <DequeuedMessage> messages = new List <DequeuedMessage>();
                foreach (DequeuedMessage message in queue.DequeueMessages(10, TimeSpan.FromSeconds(1)).Value)
                {
                    // Tell the service we need a little more time to process the message
                    UpdatedMessage changedMessage = queue.UpdateMessage(
                        message.MessageText,
                        message.MessageId,
                        message.PopReceipt,
                        TimeSpan.FromSeconds(5));
                    messages.Add(message.Update(changedMessage));
                }

                // Wait until the visibility window times out
                Thread.Sleep(TimeSpan.FromSeconds(1.5));

                // Ensure the messages aren't visible yet
                Assert.AreEqual(0, queue.DequeueMessages(10).Value.Count());

                // Finish processing the messages
                foreach (DequeuedMessage message in messages)
                {
                    // Tell the service we need a little more time to process the message
                    queue.DeleteMessage(message.MessageId, message.PopReceipt);
                }
            }
            finally
            {
                // Clean up after the test when we're finished
                queue.Delete();
            }
        }
Exemple #2
0
        public void Enqueue()
        {
            // Get a connection string to our Azure Storage account.  You can
            // obtain your connection string from the Azure Portal (click
            // Access Keys under Settings in the Portal Storage account blade)
            // or using the Azure CLI with:
            //
            //     az storage account show-connection-string --name <account_name> --resource-group <resource_group>
            //
            // And you can provide the connection string to your application
            // using an environment variable.
            string connectionString = ConnectionString;

            // Get a reference to a queue named "sample-queue" and then create it
            QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue"));

            queue.Create();
            try
            {
                // Add a message to our queue
                queue.EnqueueMessage("Hello, Azure!");

                // Verify we uploaded one message
                Assert.AreEqual(1, queue.PeekMessages(10).Value.Count());
            }
            finally
            {
                // Clean up after the test when we're finished
                queue.Delete();
            }
        }
 public void EnQueueMessage(string message, string queueName)
 {
     if (queue == null)
     {
         AzureKeyVaultConnection(SecureSecrets.GetSecret("AzureKeyVaultClientId"), SecureSecrets.GetSecret("AzureKeyVaultClientSecret"), SecureSecrets.GetSecret("AzureTranslatorTenantId"), new Uri(SecureSecrets.GetSecret("AzureKeyVaultUrl")));
         AzureQueueConnection(queueName).GetAwaiter();
     }
     var enqueueMessage = queue.EnqueueMessage(message);
 }
Exemple #4
0
        public void Dequeue()
        {
            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Get a reference to a queue named "sample-queue" and then create it
            QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue"));

            queue.Create();
            try
            {
                // Add several messages to the queue
                queue.EnqueueMessage("first");
                queue.EnqueueMessage("second");
                queue.EnqueueMessage("third");
                queue.EnqueueMessage("fourth");
                queue.EnqueueMessage("fifth");

                // Get the next 10 messages from the queue
                List <string> messages = new List <string>();
                foreach (DequeuedMessage message in queue.DequeueMessages(maxMessages: 10).Value)
                {
                    // "Process" the message
                    messages.Add(message.MessageText);

                    // Let the service know we finished with the message and
                    // it can be safely deleted.
                    queue.DeleteMessage(message.MessageId, message.PopReceipt);
                }

                // Verify the messages
                Assert.AreEqual(5, messages.Count);
                Assert.Contains("first", messages);
                Assert.Contains("second", messages);
                Assert.Contains("third", messages);
                Assert.Contains("fourth", messages);
                Assert.Contains("fifth", messages);
            }
            finally
            {
                // Clean up after the test when we're finished
                queue.Delete();
            }
        }
Exemple #5
0
        public void Peek()
        {
            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Get a reference to a queue named "sample-queue" and then create it
            QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue"));

            queue.Create();
            try
            {
                // Add several messages to the queue
                queue.EnqueueMessage("first");
                queue.EnqueueMessage("second");
                queue.EnqueueMessage("third");
                queue.EnqueueMessage("fourth");
                queue.EnqueueMessage("fifth");

                // Get the messages from the queue
                List <string> messages = new List <string>();
                foreach (PeekedMessage message in queue.PeekMessages(maxMessages: 10).Value)
                {
                    // Inspect the message
                    messages.Add(message.MessageText);
                }

                // Verify the messages
                Assert.AreEqual(5, messages.Count);
                Assert.Contains("first", messages);
                Assert.Contains("second", messages);
                Assert.Contains("third", messages);
                Assert.Contains("fourth", messages);
                Assert.Contains("fifth", messages);
            }
            finally
            {
                // Clean up after the test when we're finished
                queue.Delete();
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Message sender");
            var cert  = GetCert("sugarsus-sender1");
            var cred  = new ClientCertificateCredential(_tenantId, _clientId, cert);
            var queue = new QueueClient(new Uri(_queueUri), cred);
            var count = 0;

            Console.WriteLine("Press any key to send message or 'x' to stop.");
            var key = Console.ReadKey();

            while (key.KeyChar != 'x')
            {
                var resp = queue.EnqueueMessage($"{count}. Test {DateTime.Now}");
                ++count;
                key = Console.ReadKey();
            }
            Console.WriteLine();
            Console.WriteLine($"Sent {count} message(s).");
            Console.ReadLine();
        }