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
€65.24
List Price:  €93.21
You save:  €27.96
£55.79
List Price:  £79.71
You save:  £23.91
CA$95.78
List Price:  CA$136.84
You save:  CA$41.05
A$107.15
List Price:  A$153.08
You save:  A$45.92
S$95.25
List Price:  S$136.08
You save:  S$40.82
HK$547.16
List Price:  HK$781.69
You save:  HK$234.53
CHF 63.78
List Price:  CHF 91.12
You save:  CHF 27.33
NOK kr771.03
List Price:  NOK kr1,101.52
You save:  NOK kr330.49
DKK kr486.66
List Price:  DKK kr695.26
You save:  DKK kr208.59
NZ$117.65
List Price:  NZ$168.07
You save:  NZ$50.42
د.إ257.05
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,682.75
List Price:  ৳10,975.83
You save:  ৳3,293.07
₹5,839.27
List Price:  ₹8,342.17
You save:  ₹2,502.90
RM334.02
List Price:  RM477.20
You save:  RM143.17
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,488.62
List Price:  ₨27,842.08
You save:  ₨8,353.45
฿2,593.98
List Price:  ฿3,705.84
You save:  ฿1,111.86
₺2,266.58
List Price:  ₺3,238.11
You save:  ₺971.53
B$358.23
List Price:  B$511.78
You save:  B$153.55
R1,308.04
List Price:  R1,868.72
You save:  R560.67
Лв127.69
List Price:  Лв182.42
You save:  Лв54.73
₩96,593.58
List Price:  ₩137,996.75
You save:  ₩41,403.16
₪262.11
List Price:  ₪374.46
You save:  ₪112.34
₱4,037.82
List Price:  ₱5,768.57
You save:  ₱1,730.74
¥10,982.62
List Price:  ¥15,690.13
You save:  ¥4,707.51
MX$1,188.90
List Price:  MX$1,698.50
You save:  MX$509.60
QR255.36
List Price:  QR364.82
You save:  QR109.45
P960.21
List Price:  P1,371.80
You save:  P411.58
KSh9,275.87
List Price:  KSh13,251.81
You save:  KSh3,975.94
E£3,354.25
List Price:  E£4,792
You save:  E£1,437.74
ብር4,018.25
List Price:  ብር5,740.61
You save:  ብር1,722.35
Kz58,443.04
List Price:  Kz83,493.64
You save:  Kz25,050.60
CLP$66,028.30
List Price:  CLP$94,330.18
You save:  CLP$28,301.88
CN¥506.69
List Price:  CN¥723.88
You save:  CN¥217.18
RD$4,095.54
List Price:  RD$5,851.02
You save:  RD$1,755.48
DA9,393.81
List Price:  DA13,420.31
You save:  DA4,026.49
FJ$158.42
List Price:  FJ$226.32
You save:  FJ$67.90
Q544.03
List Price:  Q777.22
You save:  Q233.19
GY$14,645.70
List Price:  GY$20,923.32
You save:  GY$6,277.62
ISK kr9,806.99
List Price:  ISK kr14,010.59
You save:  ISK kr4,203.60
DH708.51
List Price:  DH1,012.20
You save:  DH303.69
L1,235.26
List Price:  L1,764.74
You save:  L529.47
ден4,024.43
List Price:  ден5,749.43
You save:  ден1,725
MOP$564.37
List Price:  MOP$806.28
You save:  MOP$241.91
N$1,312.44
List Price:  N$1,875
You save:  N$562.55
C$2,589.99
List Price:  C$3,700.15
You save:  C$1,110.15
रु9,350.18
List Price:  रु13,357.97
You save:  रु4,007.79
S/262
List Price:  S/374.30
You save:  S/112.30
K266.57
List Price:  K380.83
You save:  K114.26
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,865.62
List Price:  ZK2,665.29
You save:  ZK799.66
L324.62
List Price:  L463.77
You save:  L139.14
Kč1,642.25
List Price:  Kč2,346.17
You save:  Kč703.92
Ft25,489.50
List Price:  Ft36,415.13
You save:  Ft10,925.63
SEK kr767.15
List Price:  SEK kr1,095.98
You save:  SEK kr328.82
ARS$61,365.44
List Price:  ARS$87,668.68
You save:  ARS$26,303.23
Bs484.79
List Price:  Bs692.59
You save:  Bs207.79
COP$272,495.59
List Price:  COP$389,296.10
You save:  COP$116,800.51
₡35,128.88
List Price:  ₡50,186.26
You save:  ₡15,057.38
L1,728.92
List Price:  L2,470
You save:  L741.07
₲521,305.22
List Price:  ₲744,753.66
You save:  ₲223,448.44
$U2,682.06
List Price:  $U3,831.68
You save:  $U1,149.62
zł282.11
List Price:  zł403.03
You save:  zł120.92
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.