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
€66.52
List Price:  €95.03
You save:  €28.51
£55.40
List Price:  £79.15
You save:  £23.74
CA$97.77
List Price:  CA$139.67
You save:  CA$41.90
A$107.48
List Price:  A$153.55
You save:  A$46.07
S$94.07
List Price:  S$134.39
You save:  S$40.32
HK$544.73
List Price:  HK$778.22
You save:  HK$233.49
CHF 61.85
List Price:  CHF 88.36
You save:  CHF 26.51
NOK kr773.61
List Price:  NOK kr1,105.21
You save:  NOK kr331.59
DKK kr496.19
List Price:  DKK kr708.87
You save:  DKK kr212.68
NZ$119.31
List Price:  NZ$170.45
You save:  NZ$51.14
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,370.95
List Price:  ৳11,959.01
You save:  ৳3,588.06
₹5,916.42
List Price:  ₹8,452.40
You save:  ₹2,535.97
RM312.50
List Price:  RM446.45
You save:  RM133.95
₦117,624.49
List Price:  ₦168,042.19
You save:  ₦50,417.70
₨19,473.08
List Price:  ₨27,819.88
You save:  ₨8,346.79
฿2,426.48
List Price:  ฿3,466.55
You save:  ฿1,040.07
₺2,418.28
List Price:  ₺3,454.83
You save:  ₺1,036.55
B$406.67
List Price:  B$580.99
You save:  B$174.31
R1,268.60
List Price:  R1,812.36
You save:  R543.76
Лв130.09
List Price:  Лв185.85
You save:  Лв55.76
₩98,070.61
List Price:  ₩140,106.88
You save:  ₩42,036.26
₪261.37
List Price:  ₪373.41
You save:  ₪112.03
₱4,133.88
List Price:  ₱5,905.80
You save:  ₱1,771.92
¥10,806.63
List Price:  ¥15,438.71
You save:  ¥4,632.07
MX$1,423.91
List Price:  MX$2,034.25
You save:  MX$610.33
QR255.44
List Price:  QR364.93
You save:  QR109.49
P956.94
List Price:  P1,367.12
You save:  P410.17
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,475.04
List Price:  E£4,964.56
You save:  E£1,489.51
ብር8,733.50
List Price:  ብር12,476.97
You save:  ብር3,743.46
Kz63,853.79
List Price:  Kz91,223.61
You save:  Kz27,369.81
CLP$68,157.66
List Price:  CLP$97,372.26
You save:  CLP$29,214.60
CN¥506.84
List Price:  CN¥724.09
You save:  CN¥217.25
RD$4,224.90
List Price:  RD$6,035.83
You save:  RD$1,810.93
DA9,349.94
List Price:  DA13,357.64
You save:  DA4,007.69
FJ$158.89
List Price:  FJ$226.99
You save:  FJ$68.10
Q540.76
List Price:  Q772.55
You save:  Q231.78
GY$14,655.30
List Price:  GY$20,937.04
You save:  GY$6,281.74
ISK kr9,679.61
List Price:  ISK kr13,828.61
You save:  ISK kr4,149
DH699.78
List Price:  DH999.72
You save:  DH299.94
L1,274.52
List Price:  L1,820.82
You save:  L546.30
ден4,093.48
List Price:  ден5,848.08
You save:  ден1,754.59
MOP$561.60
List Price:  MOP$802.33
You save:  MOP$240.72
N$1,270.52
List Price:  N$1,815.10
You save:  N$544.58
C$2,577.69
List Price:  C$3,682.57
You save:  C$1,104.88
रु9,455.06
List Price:  रु13,507.81
You save:  रु4,052.75
S/265.82
List Price:  S/379.77
You save:  S/113.94
K281.99
List Price:  K402.86
You save:  K120.87
SAR262.75
List Price:  SAR375.38
You save:  SAR112.62
ZK1,938.58
List Price:  ZK2,769.51
You save:  ZK830.93
L331.04
List Price:  L472.94
You save:  L141.89
Kč1,685.42
List Price:  Kč2,407.85
You save:  Kč722.43
Ft27,354.11
List Price:  Ft39,078.98
You save:  Ft11,724.86
SEK kr771.99
List Price:  SEK kr1,102.90
You save:  SEK kr330.90
ARS$70,181.20
List Price:  ARS$100,263.16
You save:  ARS$30,081.95
Bs485.08
List Price:  Bs693
You save:  Bs207.92
COP$308,906.07
List Price:  COP$441,313.30
You save:  COP$132,407.23
₡35,572.52
List Price:  ₡50,820.06
You save:  ₡15,247.54
L1,770.13
List Price:  L2,528.86
You save:  L758.73
₲548,589.81
List Price:  ₲783,733.33
You save:  ₲235,143.51
$U2,994.50
List Price:  $U4,278.05
You save:  $U1,283.54
zł289.22
List Price:  zł413.19
You save:  zł123.97
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.