1
00:00:00,330 --> 00:00:07,440
In this video, we are going to receive and delete message into Q on Amazon using the SDK.

2
00:00:07,560 --> 00:00:13,450
So that means we are in here the use case three receive and delete message to Q on Amazon space.

3
00:00:13,560 --> 00:00:17,820
So basically in the last video we have created the Q and send message to Q.

4
00:00:17,820 --> 00:00:21,030
So that means in this queue we have one item now.

5
00:00:21,030 --> 00:00:27,630
So in this video we will receive and delete message into the queue why we should receive and after that

6
00:00:27,780 --> 00:00:34,530
delete message in the same time, because you can think that we are in here and we are a consumer replication.

7
00:00:34,530 --> 00:00:39,780
When in consumer replication, subscribe to Q and consume a Q record.

8
00:00:39,810 --> 00:00:47,100
It should be received the item from the Q and delete message after process their operation after perform

9
00:00:47,100 --> 00:00:48,030
the business logic.

10
00:00:48,030 --> 00:00:55,620
It should delay to Q otherwise the Q will be calculate the visibility timeout, and during the timeout

11
00:00:55,800 --> 00:00:58,380
we can't see any Q record in the Amazon.

12
00:00:58,800 --> 00:01:06,210
Q For the purpose when whenever any consumer application received the Q record after the successful

13
00:01:06,210 --> 00:01:09,480
processing the item, it should delete the message in the Q.

14
00:01:09,480 --> 00:01:15,120
So we will act as a consumer application and we will perform, receive and delete message in the Q.

15
00:01:15,120 --> 00:01:20,880
So for that purpose, please open the Visual Studio code and see that we are using the receive message

16
00:01:20,880 --> 00:01:21,270
command.

17
00:01:21,270 --> 00:01:25,800
After the receiving message, we will perform business logic and delete message command.

18
00:01:25,800 --> 00:01:27,090
Use the message command.

19
00:01:27,090 --> 00:01:31,290
After receiving the message, we will delete this message into the Q.

20
00:01:31,290 --> 00:01:34,680
So for that purpose, let's check the documentation.

21
00:01:35,560 --> 00:01:42,730
If you open the client a documentation, you can go to the receive message command and you can read

22
00:01:42,730 --> 00:01:44,650
the received message command documentation.

23
00:01:44,680 --> 00:01:48,100
Basically, short polling is the default behavior.

24
00:01:48,100 --> 00:01:54,050
So that means when we receive message command, use this command, this will be performed a short polling

25
00:01:54,070 --> 00:01:54,760
operation.

26
00:01:54,760 --> 00:01:58,690
But it is also optional with the using the long polling.

27
00:01:58,690 --> 00:02:00,910
But the default behavior is enough for us.

28
00:02:00,910 --> 00:02:09,760
We will use receive message API call from the Amazon case and we got the message ID that we received

29
00:02:09,760 --> 00:02:10,810
from the queue.

30
00:02:10,810 --> 00:02:17,380
And after that these can provide to run the visible to timeout after receiving any item into queue.

31
00:02:17,380 --> 00:02:22,960
And during the visible timeout we should process our record and delete our item.

32
00:02:22,960 --> 00:02:28,330
Otherwise when visible timeout finished, Amazon queue will be appear again.

33
00:02:28,330 --> 00:02:30,220
The same record under the queue.

34
00:02:30,250 --> 00:02:30,660
Okay.

35
00:02:30,670 --> 00:02:36,040
Here you can see the example usage, how we can implement the receive message command and this was the

36
00:02:36,040 --> 00:02:38,530
results message input and output parameters.

37
00:02:38,530 --> 00:02:43,260
If we look at the input parameters here, you can see the properties that we should provide a queue

38
00:02:43,330 --> 00:02:45,580
URL visible to timeout and so on.

39
00:02:45,610 --> 00:02:51,580
And here we can see the response of the receiving message command output, the response including the

40
00:02:51,580 --> 00:02:52,150
message.

41
00:02:52,150 --> 00:02:53,290
So this is important.

42
00:02:53,290 --> 00:02:54,640
So we will check the message.

43
00:02:54,640 --> 00:02:58,780
If there is any message after that, we will run the delete message command.

44
00:02:58,810 --> 00:03:04,240
If you open the delete message command, you can see the description and also example usage.

45
00:03:04,240 --> 00:03:10,450
So it is also basic configuration that we will provide the input parameters as a received handle and

46
00:03:11,380 --> 00:03:16,330
this handle will be comes from the message from the receive message command output.

47
00:03:16,330 --> 00:03:21,370
So when we check the message, we will get the message one and we will get the message one, receive,

48
00:03:21,370 --> 00:03:26,500
handle and provide these information into the input of the direct message command in order to perform

49
00:03:26,500 --> 00:03:27,910
the message in the queue.

50
00:03:28,090 --> 00:03:30,700
Of course we should also provide the queue URL.

51
00:03:30,700 --> 00:03:33,610
So here you can see the message command output.

52
00:03:33,610 --> 00:03:38,590
This is only returning a metadata, so that means it is a success or failure response.

53
00:03:38,590 --> 00:03:43,660
But before that please verify the our queue operations, including an item or not.

54
00:03:44,050 --> 00:03:50,470
If you go to a management console, go to queues and open the live queue and click the send recent message.

55
00:03:50,890 --> 00:03:56,770
Please verify that you are available message in one into the queue so now we can start the development.

56
00:03:56,770 --> 00:04:02,500
Please open the Visual Studio code and we will use, receive and Direct Message Command to perform this

57
00:04:02,500 --> 00:04:03,100
action.

58
00:04:03,100 --> 00:04:08,680
For that purpose, I have created a separate JavaScript file which is the receive and delete touches.

59
00:04:08,680 --> 00:04:15,820
So you can see that I have import both receive and delete message command and we import a script client

60
00:04:15,820 --> 00:04:18,480
and here you can see the our queue URL.

61
00:04:18,520 --> 00:04:21,640
These are the parameters of the receive message command.

62
00:04:21,730 --> 00:04:28,150
The parameters are including the URL visible to timeout wait time second max number of message and message

63
00:04:28,150 --> 00:04:29,020
attribute names.

64
00:04:29,020 --> 00:04:32,290
So these are the default values for the configurations.

65
00:04:32,290 --> 00:04:36,700
So I would like to show how you can configure when you receive any message.

66
00:04:36,700 --> 00:04:42,790
This will be performed the short polling and we are consuming replication to receive message from the

67
00:04:43,360 --> 00:04:49,480
queue and we provide the parameters and we sent this command to the client and get back to data.

68
00:04:49,540 --> 00:04:56,110
So so far we have seen the same structure with the other commands and if you scroll down you can see

69
00:04:56,110 --> 00:05:00,730
that we are looking to success and logging the error if there is an exception.

70
00:05:00,730 --> 00:05:07,390
So far this is very similar with the other commands, but this time when we received the message and

71
00:05:07,390 --> 00:05:11,230
get the data from the space, we should perform some business logic.

72
00:05:11,230 --> 00:05:12,490
You can think that.

73
00:05:12,490 --> 00:05:14,710
Put your business logic.

74
00:05:16,560 --> 00:05:22,560
After finishing the business logic successfully, I'm going to delete this message from the case for

75
00:05:22,560 --> 00:05:23,130
that purpose.

76
00:05:23,130 --> 00:05:26,310
We have a set of code that I'm going to.

77
00:05:27,090 --> 00:05:27,890
Open this code.

78
00:05:27,900 --> 00:05:33,020
You can see that the first line of code we will check data include message or not.

79
00:05:33,030 --> 00:05:39,240
If there is a message from the case, we will prepare the parameters for the delete message command

80
00:05:39,240 --> 00:05:46,740
so it is requesting to us q url and also receive handle receive handle will be comes from the data message

81
00:05:46,740 --> 00:05:48,210
zero and receive handle.

82
00:05:48,240 --> 00:05:54,480
So we should provide the handle when we delete any message from the Q and after that we are passing

83
00:05:54,480 --> 00:05:59,880
these parameters to the delete message command and send again without using the client and get back

84
00:05:59,880 --> 00:06:00,690
the response.

85
00:06:00,690 --> 00:06:04,260
And in the response we have success or failure response.

86
00:06:04,260 --> 00:06:09,840
That means message is deleted when we perform this operation successfully.

87
00:06:09,870 --> 00:06:11,940
Otherwise we are loading the exception.

88
00:06:11,940 --> 00:06:16,410
So this is the way how we can receive and delete message.

89
00:06:16,410 --> 00:06:22,350
If there is no message in the queue, I'm going to log this operation, which is a no message to delete.

90
00:06:22,350 --> 00:06:29,280
So as you can see that we get and receive message from the case and we put our business logic.

91
00:06:29,280 --> 00:06:35,760
After that we will check the data message and perform the deleting message from the Q operation.

92
00:06:35,760 --> 00:06:43,470
So now let me try to test this code for that purpose, open the terminal and go to correct lecture folder

93
00:06:43,470 --> 00:06:48,840
and I'm going to run Node Command and give the this file name, which is the receive and delete the

94
00:06:48,840 --> 00:06:50,550
JS hit enter.

95
00:06:51,090 --> 00:06:55,620
So this will receive the item and after the date item successfully.

96
00:06:55,620 --> 00:07:01,050
But now we have seen that there is no message so no message to delete.

97
00:07:01,050 --> 00:07:04,830
So let me add any message to ESCs and see what's happened.

98
00:07:04,860 --> 00:07:10,380
Please open the AWG mission console and go to our newly created queue and click the send and receive

99
00:07:10,380 --> 00:07:10,980
message.

100
00:07:11,160 --> 00:07:13,140
Before sending any message.

101
00:07:13,170 --> 00:07:19,530
I'm going to pull all message and delete all message in the queue, click the edit post settings and

102
00:07:19,650 --> 00:07:25,560
set the maximum message count as a ten and save button and click the pull for message.

103
00:07:25,980 --> 00:07:32,490
So I have some message in the queue I would like to delete and after that I will add any item in the

104
00:07:32,490 --> 00:07:33,060
queue.

105
00:07:33,330 --> 00:07:36,480
So as you can see that I have only one message available.

106
00:07:36,510 --> 00:07:40,080
I have select this message and delete this message.

107
00:07:40,900 --> 00:07:41,450
Okay.

108
00:07:41,470 --> 00:07:44,260
The polling progress is still ongoing.

109
00:07:44,260 --> 00:07:47,770
So if there is a message I would like to see in here.

110
00:07:48,310 --> 00:07:51,640
So as you can see that we don't have any message available.

111
00:07:51,640 --> 00:07:55,210
So I can stop polling and refresh this page.

112
00:07:56,480 --> 00:07:59,550
So verify that message available count is zero.

113
00:07:59,570 --> 00:08:03,130
So now I'm going to add a new item into Q.

114
00:08:03,140 --> 00:08:08,630
For that purpose, I provide any message body and please select the delivery delay.

115
00:08:08,810 --> 00:08:13,750
I don't want any delay, so select the seconds and set the zero.

116
00:08:13,760 --> 00:08:20,870
So that means this should be effect immediately to adding item into queue and click the send message.

117
00:08:21,110 --> 00:08:26,450
So I have sent a message and you can see the message available is one.

118
00:08:26,450 --> 00:08:29,240
So now let me try again from our application.

119
00:08:29,240 --> 00:08:36,320
If you come to our Node.js application and run the node receive and delete JS, hit the enter.

120
00:08:36,350 --> 00:08:41,840
This time you can see that we got 200 success and also we got the message list.

121
00:08:41,840 --> 00:08:47,450
So as you can see, that message are listed in here and this is the message ID and received handle that

122
00:08:47,450 --> 00:08:51,710
we provide to this recipient one deleting item into the queue.

123
00:08:51,740 --> 00:08:57,470
You can see that in this line of code we will use this handle and paste this parameter to the delete

124
00:08:57,470 --> 00:09:01,430
message command and if you scroll down you can see the details of the message.

125
00:09:01,430 --> 00:09:08,870
So if you go back to our message console and verify the message available, if you refresh this page,

126
00:09:08,900 --> 00:09:11,780
go to the queue and click the send and receive message.

127
00:09:11,780 --> 00:09:13,670
We can see that message available.

128
00:09:13,670 --> 00:09:20,270
Count is zero because we will consume this message from the our Node.js application and after that process,

129
00:09:20,270 --> 00:09:21,590
our business logic.

130
00:09:21,590 --> 00:09:26,450
And after that we will delete message from the queue as a consumer application.

131
00:09:26,450 --> 00:09:32,570
So that means, as you can see, that we have successfully receive and delete message to queue on the

132
00:09:32,570 --> 00:09:35,720
Amazon case using the SRC libraries.
