[Music]
hi this is Shahab with Amazon Web
Services in this section we are going to
take a look at how to use Amazon simple
queue service or sqs in your dotnet
application Amazon simple queue service
is a fully managed Message Queuing
service that makes it easy to decouple
and scale micro-services distributed
systems and server les applications
let's take a look at some
characteristics of Amazon sqs Amazon sqs
is a fast reliable scalable and fully
managed Message Queuing service it makes
it simple and cost effective to decouple
the components of a cloud application
Amazon sqs is a buffer between the
application components that receive data
and those components that process the
data in your system also ask us ensures
delivery of each message at least once
and supports multiple readers and
writers interacting with the same queue
also most of the time each message will
be delivered to your application exactly
once so you should design your system to
be idempotent now let's take a look at
the differences between Amazon sqs and
SNS they are both messaging queues but
there is a slightly differences between
them for example when it comes to
keeping the data Amazon sqs is persisted
however Amazon SNS is not also Amazon
SNS uses push mechanism to push the
notifications to the client and Amazon
SQS uses the pull mechanism so the
clients they need to pull the QD
messages from queue and at last
Amazon SNS has a one-to-many
publish/subscribe method however for sqs
it's a one-to-one send/receive mechanism
now let's take a look at Amazon s qsq
types there are two different queue
types for Amazon sqs there is the
standard queue for which the message
ordering is not guaranteed messages may
be duplicated and true put is nearly
unlimited
we have 5oq which message ordering is
preserved messages are only received
once and true put is limited now let's
take a look at some key concepts when a
consumer takes a message from the queue
it's provided with a receipt handle a
receipt handle is a very important
component because you need the receipt
handle to delete the message from the
queue also the visibility timeout is a
very important concept it's the period
of time that a message is invisible to
the rest of the application after an
application component gets it from the
queue so in this way it prevents
multiple components from purchasing the
same message by locking the messages
also when the application needs more
time for processing you can change this
timeout value dynamically why a change
message visibility operation when the
process is finished the component which
received a message will delete it from
the queue and if processing fails the
lock expires a message becomes available
again now let's take a look at some more
key concepts when it comes to receiving
messages Amazon SQL supports was long
polling and short polling please
remember that short polling is the
default method also Amazon sqs supports
that letter Hughes it means that message
is that for some reason cannot be
successfully processed they will be
sidelined and isolated so you can
analyze these messages in the dead
letter Q later to determine the cause of
failure or if you want to retry the
operation now let's take a look at some
basic you operations that Amazon sqs
supports there is a full list of api is
provided in the URL i have provided in
the bottom of the screen however the
more important ones that I put it
together are create queue set queue
attributes get queue attributes get
queue URL least queues and delete queues
please remember that through the gets
here crate queue you can set delay
seconds and visible
the timeout which are very important for
the purpose of your application now
let's take a look at how to use the SQS
api's in a dotnet application interface
using visual studio in microsoft visual
studio you can always see the amazon sqs
under amazon explorer window you can
always expand the tab and see the name
of the accused that you already have
created in order to use the Amazon sqs
aps in the earning in Visual Studio I'm
going to use a sample application let's
go to file new project under visual
c-sharp
aw samples you should be able to see app
services click on SQL sample and click
OK you are allowed to choose the profile
and region in this screen you can always
change the screen in the app config file
later also in order to use Amazon SDK
for sqs you always need the proper
nougat package here this sample already
has the nougat package downloaded and
installed if you are working on a new
application you just need to right-click
on dependencies go to manage nougat
packages and search for AWS SDK AWS SDK
that sqs and you can click on it here
since its installed
I can uninstall or update it in your
case you should be able to see the
install and click on install it since
this is a console application everything
gets started from the program that CS
file let's take a look at program that
CS as you can see we are importing
Amazon that sqs and SQS that model these
libraries are required for you to use
SQS api's in your dotnet application if
you are creating a new application you
should import this libraries or use them
in order to use Amazon sqs you need to
create a client this client should be of
type Amazon sqs client after you have
the client created you can use this
client to create a queue to least queues
to send messages to the queues or to
receive messages from the queue for each
operation you will need a request for
example sqs request to create a queue
just requires a queue name here in this
scenario we can call it my AWS queue to
create a queue name also after you
created a queue to lease the queue you
also need a least queue request the
lease queue request doesn't enforce you
to pass any arguments when you want to
send a message you need to create a send
message request the minimum information
you need to provide for the send message
request is the queue URL and a message
body and I'm going to call it this is my
new message text from AWS at last one
you want to receive a messages you need
to define an receive message request the
minimum thing you need to provide is the
queue URL after you do that the message
can have the response can have one or
more set of messages you need to go
through those messages and you need to
properly process them in a way that you
want please remember as I mentioned
before the response to receive message
will return you a receipt handle you
need duties receipt handle if you need
to delete the request when you are done
with processing and you need to delete
the process the request after you are
done processing to order to call the
delete request you need to provide the
queue name or URL and also the receipt
handle
always also you can catch the sqs
exception to any sqs api carl that can
tell you more information about if
anything goes wrong now let's run this
application start without debugging and
let's see how it works so it is create a
queue called my queue and then print
list of Amazon sqs queues and you can
see my a SS queue is here now then we
sent a message to my queue in this case
is my a SS queue and we got it and it
says that it could receive the message
this is my new message text from AWS and
at last we deleted the message in this
example I did show you how to use SQS
api's in your dotnet application in this
video we went over how to use Amazon sqs
in your dotnet application thank you for
watching
[Music]