Lab 9: Azure Queues, Visibility timeouts, Peek and De-Queue

Azure Step by Step Training Lab 9: Azure Queues, Visibility timeouts, Peek and De-Queue
28 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.10
List Price:  €95.86
You save:  €28.76
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.49
List Price:  CA$143.56
You save:  CA$43.07
A$111.96
List Price:  A$159.95
You save:  A$47.99
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.16
List Price:  HK$777.41
You save:  HK$233.24
CHF 62.56
List Price:  CHF 89.37
You save:  CHF 26.81
NOK kr792.29
List Price:  NOK kr1,131.89
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.74
List Price:  NZ$176.78
You save:  NZ$53.04
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,330.24
List Price:  ৳11,900.85
You save:  ৳3,570.61
₹5,945.56
List Price:  ₹8,494.03
You save:  ₹2,548.46
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,149.19
List Price:  ₦154,505.46
You save:  ₦46,356.27
₨19,403.53
List Price:  ₨27,720.51
You save:  ₨8,316.98
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,454.67
List Price:  ₺3,506.82
You save:  ₺1,052.15
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,282.09
List Price:  R1,831.63
You save:  R549.54
Лв131.15
List Price:  Лв187.37
You save:  Лв56.21
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪254.67
List Price:  ₪363.83
You save:  ₪109.16
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,949.58
List Price:  ¥15,642.93
You save:  ¥4,693.35
MX$1,405.49
List Price:  MX$2,007.92
You save:  MX$602.43
QR254.12
List Price:  QR363.05
You save:  QR108.92
P963.49
List Price:  P1,376.48
You save:  P412.98
KSh8,999.72
List Price:  KSh12,857.29
You save:  KSh3,857.57
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,689.79
List Price:  ብር12,414.52
You save:  ብር3,724.72
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,143.42
List Price:  CLP$98,780.55
You save:  CLP$29,637.13
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,244.94
List Price:  RD$6,064.47
You save:  RD$1,819.52
DA9,440.04
List Price:  DA13,486.35
You save:  DA4,046.31
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q537.12
List Price:  Q767.35
You save:  Q230.22
GY$14,584.29
List Price:  GY$20,835.60
You save:  GY$6,251.30
ISK kr9,693.35
List Price:  ISK kr13,848.23
You save:  ISK kr4,154.88
DH701.59
List Price:  DH1,002.31
You save:  DH300.72
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,127.89
List Price:  ден5,897.23
You save:  ден1,769.34
MOP$558.06
List Price:  MOP$797.27
You save:  MOP$239.20
N$1,283.39
List Price:  N$1,833.49
You save:  N$550.10
C$2,565.21
List Price:  C$3,664.75
You save:  C$1,099.53
रु9,482.30
List Price:  रु13,546.73
You save:  रु4,064.42
S/259.58
List Price:  S/370.84
You save:  S/111.26
K282.68
List Price:  K403.85
You save:  K121.16
SAR262.90
List Price:  SAR375.59
You save:  SAR112.68
ZK1,929.21
List Price:  ZK2,756.13
You save:  ZK826.92
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.83
List Price:  Ft39,690.03
You save:  Ft11,908.20
SEK kr772.17
List Price:  SEK kr1,103.14
You save:  SEK kr330.97
ARS$71,242.69
List Price:  ARS$101,779.64
You save:  ARS$30,536.94
Bs481.71
List Price:  Bs688.19
You save:  Bs206.47
COP$305,135.87
List Price:  COP$435,927.07
You save:  COP$130,791.20
₡35,171.10
List Price:  ₡50,246.58
You save:  ₡15,075.48
L1,769.55
List Price:  L2,528.04
You save:  L758.48
₲543,563.42
List Price:  ₲776,552.46
You save:  ₲232,989.03
$U3,109.25
List Price:  $U4,441.97
You save:  $U1,332.72
zł286.15
List Price:  zł408.81
You save:  zł122.65
Already have an account? Log In

Transcript

So welcome to lab nine. And in lab nine, we will be talking about as your cues end to end. So this lab nine is dedicated for as your cues. So this is going to be approximately a 30 minutes of video and it's 30 minutes of video, I have six important agenda which I'm going to cover first is I will start with the basics of as your cues and I will talk about in the FIFA style of reading, then I will talk about two important ways of reading one is called a peek message and the other one is called as a good message. So there is a good message as well as there is a good messages, then we'll talk about something called as dq. So dq is a different process, you know, which is very more sophisticated than reading.

So we'll talk about that. We'll talk about visibility timeout, and then we'll talk about message ID and policy ID and how both of them help us to create decoupled updates in as your cues. So this is going to be a 30 minutes of video completely dedicated to as your cues. So let us start. So let us first Try to understand why do we need queues The main purpose of queues is to decouple two systems means what for example, now think about it, you have system one, and you have system two. So system one is making a call to system two, and system two is responding back, but the system two can only respond back, if it is up and running.

If the system is down, then this call will terminate without a response. So, what we can do is we can tailor the architecture over here we can we can put a queue in between right. So, the system one can go and write it on the queue and the system two if it is up and running, he can read from the queue. If the system is not up and running, whenever he comes alive, he will actually read and process this data and send the response back to the queue. So, by putting a queue in between both system one and system two do not have to be running all the time, right and that helps us to decouple two systems that helps us to communicate between two systems. In a more decoupled manner.

Now, the data structure of queues is is faithful it follows the faithful architecture for means, first in first out, for example, you can see here that there are three chunks of data which is written data one, data two and data three. So, first data one was written, then data two was written and then data three. So, did whenever, whenever the client tries to read data, he will first read data one and not data three. Again if he tries to read he will read data two and then he will read data three. So, first in first out so whatever you write first will be read first. So, that's how the architecture of the queue is.

So, now let us see how we can go and create an queue. So, the first thing is in order to create a queue we need to create an Azure storage account so, if you remember in the past videos you know when we created a table when we created a blob, right, we first created a story storage account right. So, you can see that I have created a storage account here called a shift ship account. And then inside this I can go and I can create an queue. So, you can see that is this Q zero so I can go and click on this and I will let's create a queue here called as my kills. So that as you can see, now my queue has been created and inside this my queue now we can go and we can add message and we can then do people first in first out right.

So now let us go ahead and write a simple C sharp code and let us see that how we can go and push messages into this queue out here right. So that you can see I have created a simple console application. So the first thing is, we need to go and add the as your namespace. Remember, I've been saying this in all my previous videos, so you need to first go and add the as your package, right so I'm going to go and add as your package. So Windows as your storage so that it is I'll install this and as a default step you know you need to first go and create first go and create a connection. So from the shisha program now, the first thing what we need to do is we have done this in done this for blobs, we have done this for tables right.

So, first thing is we need to go go and get access to the as your storage account you can see and also you can see I pasted the connection string, this connection string I have received from this access. So if you remember from the access keys, we can get the connection string. So this connection string I have pasted right out here, right? And so, you can see here I'm first creating unforced referencing the storage account. In that storage account. I am referencing the the Client cloud cloud queue, right?

So that's a class we need to refer. And in that I'm referring my queue. So if you remember, we have created this my queue out here. So that's what I'm referring I think it is plural, my queues fine. So we need to go and change this to my queues. And in case if this queue is not created, we can go and we can say that please go and create this queue if it does not exist.

So now let us first start with how we can go and write a message, right simple one, I want to go and write a message to the queue, right. So in order to go and write a message, you need to go and create an object of the cloud queue message. You can see here, I've created a object of cloud queue message. And in this you can go and you can put a message here you can see this is like just an hello world, which I'm putting. Now remember, you can put a message which is a byte content, raw content, string, content, integer, right, a lot of things we can put out here. So but I'm putting at this moment, a simple string.

So first, I'm putting a message Call it hello world. And the next message I'm putting it as hello world one. So I'm, I'm pushing two messages inside this queue. One is hello world. And the other one is a Hello World one, right? So, so let me go and run this program out here.

So let's go and run this program out here. So, let us see if this works. So there it is. It created the as your storage account, got access to the queues, and then we started adding the messages. So I've added hello world, I've added HelloWorld one. So now if I go to my Azir out here, I should see both the messages.

So there it is, you can see hello world and hello world one. So now that we know how to add data into queues, let us try to understand how to read data. Now reading data from queues is a bit complex or I can say there are two kinds of read flavors in queues. One is you can say the reading Without processing the data, which is termed as peak and the second one is read with processing the data which is termed as dq. So, there are two styles of reading one is peak and the other one is dq. Now, if you are using pig style of reading, in pig style of reading, it will always retrieve the current message.

Remember when we talk about queues, in queues, the retrieval happens using the FIFO style first in first out right, so, for example, over here you can see, first data one was pushed, then data two was pushed and then data three was pushed. So, if somebody does a peek one times 10 times 100 times right, he will always read data one. Again, I repeat this statement. If you peek numerous number of times, you will always get data one if you want to get data to then you need to delete data one to retrieve data to if you want to get Data three, then you need to delete data too. And deleting a message from a queue is an indication that you have finished processing that message and you do not want it in the queue. again repeat two important points first is queues follow the faithful style right.

So, if that is the first point, the second point is that if you want to retrieve the next message, then you have to delete the current message and deleting the current message means that you have finished processing the current message right. So, if you are doing a peek right, you will always get the first data and if you want to get the next data then after the peak do a delete. So, let us go and see example first of peak and then we will come to the dq style of reading. So, now in order to do a peak message we need to use the cue object, the reference of the cue object. And in this unit we have a function called speak message right. So, over here I can say where MSG is equal to pique message.

And then I can do a console dot write line and I can display this message as a string. Or if it is binary then you need to read it in a byte array and so on. Right? So you can see now I'm going to go and comment this below lines of code. Because we are not intending to add more messages. Now remember, that we first added hello world and then we added hello world one.

So when this peak message will run, right, it will display hello world. Remember FIFA style. The reading is in FIFA style. And if you execute this peak message continuously, it will always read HelloWorld until you issue a delete, right? So I'm going to go and run this. So let us see what happens.

So there it is, my peak message is running. And it is displaying out here hello world can you see here. Now even if I go and execute this peak message multiple times, you can see I have again, ran the debug point it still shows me HelloWorld so if I put it here again, it still shows me hello world. So until I don't delete the current message, it will not retrieve the next message. And deleting a current message is an indication that you are finished processing. Again a repeat, deleting the current message indicates that you are finished processing, right.

So that's what the use of peak messages. Now this was the peak style of reading. Now let's try to understand the other style of reading that is dq and in most of practical scenarios, you will probably use dq and not peak message. Now in dq style of reading, you will be reading the message processing it and deleting it. But when you're doing D queuing, you need to respect a golden slogan of queuing. Every message in the queue is processed only once and by only one client.

Again, I repeat this message every message Processed one only once and by only one client. So, in other words, what you need to do is when you are actually starting processing it, you have to first lock it. So, you lock it, so that it is not visible to anyone else Or else somebody else can process it and the message can get processed twice. So the so in D queuing, first you will lock the message, you will read it, you will process it and you will delete it. And while you're doing this, you should ensure that anyone else should not be able to read your message or do something or else your message can get processed twice. So, this is termed as dq.

So, in order to do dq, we should not be using the peak function, but we should be using something called as a read function. When you are reading it from the queue. It gives you ability to go and say that make this message invisible for one minute or 10 minutes or whatever it is. By default the message is invisible for 30 seconds. again repeat when you do a read by default the message is invisible for 30 seconds for other people, but if you wanted you can make it you can you can change the time, because it is possible that your processing can take more than 30 seconds right. So, let us go and see an example of how to do a dq.

So, in order to read we need to use the get message function. So, if you see here in the queue object, we have a get message function and you can see in this get message function you know we have this visibility timeout, this visibility timeout says that, when you get this message for how much time do you want that the other people cannot see this message. In case you do not provide this visibility timeout, then by default it is 30 seconds. For example, if you see now, let us say I do a get message here and then we can Go ahead and write that message to a console. So, if you see, at this moment, I can see the message you can see hello world one or hello world, I can see both of them. So, when I go here, I can see both the message right.

But if I go and execute this, after the call to the get message, this message will not be visible for 30 seconds. So you can see now, I have done a good message. Now if I go back to the browser here, and if I try to do a refresh, I should not see the Hello World one. So you can see that I'm not seeing the Hello World one. Right. So in other words, you know, when you do a get message, the get message function.

What it does is, it actually says that, yes, you want to go and process this message. So, we will make this message invisible enough for a certain time. Now, if I go and do a refresh here you can see now the scene. So, after 30 seconds, I can see that message, you can also go and provide a time here. So, for example, let us say if your processing is taking bit more time, you can go ahead here and provide a timeout. So, you can provide a timespan and see that I am expecting that this will take not 30 seconds, but a minute so, I can see here one minute.

So, you can see now, this message will not be visible for one minute. So, what you can do here is if you want to really do a dq, right remember I can just again start the presentation. So, if you see, when you say you want to do a dq that means, you will first go and lock that and how do you lock it by doing a get message. So, the lock and the read is done by using get message. You can then process it and then you can go on And deleted. So, logically after this get get message you should be doing your cue dot delete message the message object.

So, you can see this is dq dq means, you get the message you lock it and then once you're done with the processing you delete it. So, if you see now, there the message is received, it is fetched and you can see now, the time span is given off one minute. So for one minute this message is not visible to anyone you can see that hello world message is not visible to anyone. So you process the message and then immediately deleted. So once you deleted this message will not be seen. And remember he first flashed hello world.

Why did you first hello world because it is following the FIFA style. The first message which was inserted was Hello So, if it fetched HelloWorld if I again do a get, I will get hello world one. So, remember the pig style of reading you know it, it does not do any kind of locking as such, it just helps you to pick the message, but the get message style of reading will help you to lock it and then process it and delete it. Now, rather than doing a get message, you know in a single way, you can also do a bulk get message. So, you can also go and do something like this, you can see here for each where MSG, one in queue, dot get messages. So you can see get messages, you can see I want to retrieve 10 messages at one time you can give a visibility timeout.

If you don't give a visibility timeout, then by default is 30 seconds. So you can go and do a for each loop. You can use the get messages. And then once the message has been processed, you can go and you can delete them. message by using the cue dot delete message queue dot delete message and MSG one. So again, like, if you want to do well, a bulk get locked them, you can use this.

If you want to update a message, then what you can do is the first thing is you need to get a message. And then you can go and you can call q dot update message. And the update message you need to put two things one is you need to put the message what you want to update. So, for example, you can see here that I've done a good message and I can go and I can change the content. So I can say this is changed, right. And then you can go and put this updated message in the update message function.

And if you want you can also give the visibility timeout so you can give your saying that this updation will take like 20 Second so I can see or it can like so you can see or you can see it in the time span. That is our Sousou hours and we'll take a minute and zero seconds right. And unit to then provide something called as message update fields. This message update field says that what are you updating? One is that I'm updating the message as well as I have updated the time span the the visibility time right. So over here, I need to say message fields.

So, I have updated the content as well as I have updated the I have also updated the visibility. So with this, you know, it just tells you know that we are in sync with what message we have given right. So, update message, the message what has to be updated, in case you want to go and change the visibility time. So if you actually go and change the visibility time, they To save both the content and the visibility, if you don't change the visibility time, you can go and just remove this thing. At this moment, I'm updating both the visibility time by default is 30 seconds, I have updated it to one minute, right. So this will actually go and update the message.

So if I run this it will go and it will update the message. Also, while you're updating the message, please ensure that you put a proper visibility time. So you can see I have fetched a message here, which is if we go and do a quick watch, message dot a string if we do that, you can see this is hello world one. And this hello world one is changed. And then I'm saying update message. Right.

So if I now go and do a run again, I should see the updated data. So if I go now and if I get the message and if ok you can see now I have given the timestamp as one minute right. So, if I given the timestamp as one minute, this message only retrieved you can see the message is null. Right. So, the visibility time has to be finished. Yeah, it is still null.

So once the one minute has passed, you know, then only I will be able to retrieve this message. Okay, and what is happening is, every time I'm calling a get message it's actually incrementing this time to one minute right. So, let us wait for some time and let us see that if this message gets updated, right, so now rather than going to the program, what I'm doing is I've gone to the website you can see now this message out here this is changed. So you can see if I go to my queues, it is changed right? So what was happening out here is why I was getting it now because every time I do a get you know, I was it was having that one minute time period, right? I don't know if I run, I should be able to get the message because I waited for one minute.

Yeah, there it is. So now if I do a quick watch dot string, I should be able to get the message. But remember now it is locked for a minute, right? So if I do a refresh, this message is not senior Why? Because the visibility time has started. So after one minute only this thing will be visible out here.

Right? So that's how you update the message. You need to go and provide the content. What do you need to update the message? What do you need to update and the visibility timeout and over here I am saying I'm updating content. And I'm also updating the visibility time in case you're just updating the visibility time then you don't need the content.

If you're upgrading just the content and not the visibility, then you don't need the visibility thing. Now there are two important properties on the queue message you know which I want to point out, especially when you're doing disconnected kind of updates. You need to understand both these properties. So on this message, you know, we have this ID property. And there is one more property here called as the pop received ID. So what is the importance of this?

Both of these things, you know, help us to handle concurrency in as your queues. Now, here is the image in which I'm flashing. Now, think about it, you have a message. Now, every message in your queue has an ID for example, you can see that I have given an ID there x 76943. Now think about it there are there is user a and there is user B. Now user a fetches this message and he wants to do an update, right?

Or else he wants to dq it right. So what as your cue does is he actually gives him a pop received ID. So for example, he will fetch this message ID x 76943. And the as your cue will allocate him a unique ID 1001. Now please note here, the ID I have given 1001 x 76943. In actual scenarios, these IDs are geo ID.

So they are quite long. They're long. They're unique. They are geo ID. So just you know, in that image, I've just shown it in a in a small way. But actually, they are big geo IDs, right.

So now this user a fetch as a message, let us say that he fetches this message and keeps a visibility timeout as 30 seconds or one minute. So what is your cue says is that here is a receipt ID. And this 30 seconds is only for you. So if when you come within the 30 seconds, I will check that the opposite ID to ensure that I'm not upgrading the wrong person. Now think about it. Within that 30 seconds, let us say user B comes in.

So user B or client B comes in and he says I want to update x 76943. But what is your cue does is he says this message is locked by a pop received ID One, two Little One, and your policy ID is 1002. So you won't be able to update it. So by using the policy ID, as your cue identifies that who has locked that message, and that that's how he implements the visibility timeout. And also, I would like to bring to notice that the message ID and the policy ID are very important properties, you know, if you are working with a disconnected queue updates, so if you are if you are implementing disconnected architecture, for updation of the cues, then this is very important. What do you mean by disconnect architecture, this kind of architecture means, for example, now, I go and get this message from online, right.

And let's say I put a visibility timeout of one minute or whatever it is here, right. So what I want to do is I want to create a separate message object so I'll create a separate New Message object So this is a cloud message a cloud cue message. So in this, I need to provide a, so I want to create a new fresh object itself, right. And I want to update that fresh object. And once I'm done with the update, then only I will go and update to online. So over here, you can see now I'm creating a fresh message, new object.

So in this now, I need to go and provide him the ID. And also the policy ID dot policy ID. So you can see now I have created a fresh new message object. The one message MSG is the old one, which I've got from online. But here I have used the new keyword and created a fresh object. And let us say I'm manipulating this object offline.

So I'll go and say, okay, set message content, updated by Bob ID by Bob received, ID and Id right We can then go and update this message, right, so I'm going to go and update this message. So update message, message new. Now you can see here, you can turn this as a disconnected architecture. In other words, we are creating a fresh copy, we are updating that fresh copy. And we are going online to update it. But when we go online to update it, we still need to provide the received ID or as the as your key will cue as your cue will refuse to update it right.

So in such kind of a disconnected scenario as well. This message ID and policy It is important, so you can see it now. I'm first fetching the message. Now you can see this message ID is a it's a Jew ID. You can see the policy applied is also a big number, right? So I go ahead, I take this, I copy it to a new message, I update that message and then I use the update message to go and update it.

So We can see now it has updated it. So now let us go online and check that if the message has been updated to updated by policy, ID and ID. So there you can see that the message has been updated. Right, so updated by policy ID. So this is the same message, you know, which was sent when we had created the decoupled message cloud queue message object, right? So that brings us to the end of this are 25 to 30 minutes of training in this training, we were trying to understand what is as your queues, what is fee for how to do an add update, what is a visibility timeout, how to create decoupled updates, what is a policy ID and so on.

So I hope that you enjoyed this session. Thank you very much.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.