Azure in a Day Training Azure Queues Module 1: Azure Queues Overview Module 2: Enqueuing a Message – DEMO: Creating Queues – DEMO: Enqueuing a Message.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
CS Data Structures II Review COSC 2006 April 14, 2017
Designing an ADT The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT What data does.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Data Structures Michael J. Watts
Page 1 Queue Storage Jeff Chu | Page 2 Agenda Queue Storage Overview Programming Queue Storage Queue Storage tips Lab Time.
E.G.M. Petrakisstacks, queues1 Stacks  Stack: restricted variant of list  elements may by inserted or deleted from only one end : LIFO lists  top: the.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
Stacks, Queues, and Deques
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
CPSC 252 Exception Handling Page 1 Exceptions and exception handling Client programmers can make errors using a class attempting to dequeue an item from.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 8 Stacks and Queues Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Jimmy Narang 1. A service in the cloud has to: Be able to handle arbitrary node failures Be available all the time Be able to scale up or down on demand.
Stacks and Queues Introduction to Computing Science and Programming I.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Exceptions Handling Exceptionally Sticky Problems.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
CSC 205 Programming II Lecture 22 Carwash Simulation.
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
CSI 1340 Introduction to Computer Science II Chapter 6 Lists Plus.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
5 Worker Role Your Code public class WorkerRole : RoleEntryPoint { public override void Run() { while (true) { Thread.Sleep(1000); //Do something.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Data Structures Using C, 2e
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Pointers and Linked Lists
Data Virtualization Tutorial… CORS and CIS
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stack and Queue APURBO DATTA.
Hello Farmington! 4:30-5:30, then dinner.
Data Structures and Database Applications Queues in C#
Pointers and Linked Lists
Stacks, Queues, and Deques
Windows Azure Storage Queue Storage.
Stacks, Queues, and Deques
Lesson Objectives Aims
Bob Tabor | Microsoft Azure Fundamentals: Data Understanding Microsoft Azure Storage Queues Bob Tabor |
Please use speaker notes for additional information!
CSE 1030: Data Structure Mark Shtern.
Introduction to Building Applications with Windows Azure
Stacks and Queues Prof. Michael Tsai 2017/02/21.
Stacks and Queues CSE 373 Data Structures.
Stacks, Queues, and Deques
Troubleshooting.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Presentation transcript:

Azure in a Day Training Azure Queues Module 1: Azure Queues Overview Module 2: Enqueuing a Message – DEMO: Creating Queues – DEMO: Enqueuing a Message Module 3: Dequeuing a Message – DEMO: Dequeuing a Message Module 4: 2-Phase Dequeue – DEMO: Handling Delete exceptions Module 5: Handling Poison Messages – DEMO: Handling Poison Messages Module 6: General Guidance – DEMO: Exponential Backoff

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages

What are Queues FIFO (First-In-First-Out) structures Items are enqueued on the bottom (rear) and dequeued from the top (front) Check-out line metaphor Purpose – Loose coupling of systems – Buffer

Loose Coupling of Systems Web Role Azure Queue Worker Role In Azure Hosted ApplicationsIn Any Application Producer Consumer

Loose Coupling of Systems Producer Azure Queue Consumer

The Process – Very Simplified Producers Add Messages to the rear of the queue Producer Consumer 1 Azure Queue M1 M2 M3 M4 Consumer 2 MSG Azure Queue MSG M1 M2 Consumers Get Messages from the top of the queue 1.Get Message 2.Operate on the message 3.Delete the message

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance

Common Queue Operations Queue Operations – Create – CreateIfNotExist – Delete Message Operations – AddMessage – Enqueue – GetMessage(s) – DeleteMessage 2 Phase Dequeue

Creating a Queue 1.Get reference to CloudStorageAccount 2.Get a CloudQueueClient 3.Get a reference to a Queue 4.Call Create() or CreateIfNotExist()

Creating Queues - Notes Create() & CreateIfNotExist() issue PUT to appropriate URI: Returns – 201 Created – if queue did not exist and was created – 204 No Content – if queue existed *** Do not create queue more than once – In most cases, you can think of this as a setup process like creating a database – Not wrong to put in application initialization

DEMO Creating Queues

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance

Enqueuing a message 1.Get reference to CloudStorageAccount 2.Get a CloudQueueClient 3.Get a reference to a Queue 4.Create an instance of a CloudQueueMessage 5.Add the message to the queue

Enqueuing a message (code)

CloudQueueMessage Message can be string or byte[] (overloaded constructor) Messages – Have xml wrapper – Are base64 encoded – Have 8 KB limit PopReceipt – Indicates that a message has been popped – Used for deleting a message DequeueCount – Number of times a message has been dequeued – Used to deal with poison messages

CloudQueue.AddMessage(…) Pushes a message onto the rear of the queue Time-to-live – Length of time message will live on the queue if not deleted – Default: 7 days – Can be set with overload to AddMessage Issues a POST Returns 201 Created

DEMO Enqueuing a message

END OF MODULE 2

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages

Dequeuing a message 1.Get reference to CloudStorageAccount 2.Get a CloudQueueClient 3.Get a reference to a Queue 4.Call GetMessage(s) 5.Do some work 6.Call DeleteMessage, passing the message as a parameter (or the message id and pop receipt)

2 Phase Dequeue Phase I – Get Message(s) – Set visibilityTimeout – time that message will be invisible to other queue message consumers – You receive pop receipt when getting message Phase II – Delete Message – Must pass valid pop receipt – Exception thrown if bad pop receipt

The Process Producer M5 Azure Queue M4 M3 M2 M1 Azure Queue A producer enqueues a message to the bottom (rear) of a specific queue M5 Consumer 1 M1 1.A consumer gets a lease on message(s) at top of a specific queue The consumer gets a copy of the message The consumer gets the message’s valid pop receipt The message on the queue is made invisible to other consumers for a period of time 2.The message becomes visible if it is not deleted within the VisibilityTimeout period 3.The consumer performs some operation on the message If successful, the consumer deletes the message, passing the pop receipt If the pop receipt is valid, the message is deleted from the queue Otherwise an error is thrown Why would it fail? The message was made visible and another consumer got a lease on it Race condition Rcpt1 DeleteMessage() Exception

GetMessage and DeleteMessage Getting a message CloudQueueMessage GetMessage() CloudQueueMessage GetMessage(TimeSpan visibilityTimeout) Getting multiple messages IEnumerable GetMessages(int messageCount) IEnumerable GetMessages(int messageCount, TimeSpan visibilityTimeout) Deleting a message void DeleteMessage(CloudQueueMessage message) void DeleteMessage(string messageId, string popReceipt)

PopReceipt Property of CloudQueueMessage Set every time a message is popped from the queue (GetMessage or GetMessages) Used to identify the last consumer to pop the message A valid pop receipt is required to delete a message An exception is thrown if an invalid pop receipt is passed

VisibilityTimeout If timeout expires prior to message being deleted, the message will be exposed to other consumers VisibilityTimeout details – Default: 30 seconds – Minimum:1 second – Maximum:2 hours Notes – Ensure you set the timeout to a span that is longer than it will take you to process the message

DEMO Simple Dequeue

END OF MODULE 3

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance

Illustrating the 2 Phase Dequeue Race Condition Consumer 1 Azure Queue M4 M3 M2 M1 Azure Queue M5 Rcpt1 Consumer 2 M1 Rcpt1Rcpt2 Step 1: Consumer 1 calls GetMessage(5) Azure assigns a PopReceipt “Rcpt1” to the message Consumer 1 Receives the message and the PopReceipt Message not visible to other consumers for VisibilityTimeout (5) M1 Step 2: VisibilityTimeout (5 seconds here) expires Message is now visible to other consumers Step 3: Consumer 2 calls GetMessage() Azure assigns a PopReceipt “Rcpt2” to the message Consumer 2 Receives the message and the PopReceipt Message not visible to other consumers for VisibilityTimeout (30) M1 Step 4: Consumer 1 calls DeleteMessage, passing PopReceipt “Rcpt1” “Rcpt1” is no longer a valid PopReceipt Azure throws an Exception (404)

Handling Delete Exceptions * Taken from Steve Marx’ blog postTaken from Steve Marx’ blog post

Idempotency Repeated actions have the same effect as one i.e. The action can be run multiple times without issue You should design your queue operations to be idempotent! Plan for the reality that more than one consumer will receive your queue message

DEMO Handling Delete Exceptions

END OF MODULE 4

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance

Poison messages Messages that cannot be processed and remain in the queue Poison message process 1.GetMessage(5) called (VisibilityTimeout of 5 secs) 2.Some error occurs while processing the message 3.After 5 seconds, the message is visible again 4.Repeat

Handling Poison Messages Messages have a DequeueCount Always check the DequeueCount and if it exceeds your threshold, do something with the message and delete it – Add it to a poison message queue – (or do something clever)

DEMO Handling Poison Messages

END OF MODULE 5

Agenda I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance

Azure Queue Guidance Set appropriate visibilityTimeouts when getting messages – VisibilityTimeout should be longer than it takes to process a message – Use logging to tune visibilityTimeout Message processing code should be idempotent Always handle the StorageClientException where ExtendedErrorInformation.ErrorCode == "MessageNotFound”

Azure Queue Guidance - 2 Do not create queues more than once – Can create queues in application setup – Not bad to create a queue in application init Always compare the DequeueCount to your threshold before processing a message If messages are large, consider adding the message to BLOB storage and a pointer to the queue

Azure Queue Guidance - 3 Question “chatty” queue implementations – The key is to understand the “nature” of your messages – Consider bundling messages Ensure message producer and consumer understand the message structure Do not read from Queues in a “tight loop” – Set appropriate wait times if no message is found – Use exponential backoff when possible

DEMO Exponential Backoff

Summary I.Azure Queues Overview II.Common Queue Operations A.Creating a Queue B.Enqueuing a Message C.Dequeuing a Message III.2 Phase Dequeue IV.Handling Poison Messages V.Azure Queue General Guidance