How to create and delete queue from AWS SQS

SQS
Reading Time: 8 minutes

Hello everyone! Today in this blog we will see how we can create a queue and how you can insert and delete a message from the queue and we will also see how we can delete a queue from AWS SQS. So first let us see what is SQS? It is a fully manage message queueing service that allow users to separate and scale the microservices distributor system and serverless application which means each component of the microservice or the distribute system can be scale individually without affecting the other components. Sqs is also use to send, store and receive message between software components at any volume. It ensure that message is not loss during the process and it reaches the consumer on time.

How we can create a queue in SQS?

Step 1: First I have logged into the AWS management console. Now let us search for the simple queue service.

Step 2: Now in this page we have certain information about Amazon SQS. There are producer who sends the messages into the sqs queue and consumers who pulls the messages from the sqs queue. And you can see sqs queue are use to store messages and wait for consumers to pull them.

Step 3: Next we have certain benefits and features using sqs. Then there are information about company that uses AWS SQS.

Step 4: Now let us create our queue. So we have an option here to create our queue. We will click on that option and it will redirect to a page where we can create our queue.

Step 5: First we have to select the type of queue. There are two types of queue. (I) Standard queue (ii) First in First out queue. The major difference between them is that standard queue support at least one message delivery which means your messages are deliver at least once to the consumer. And in first in first out your message is deliver exactly once to the consumer.

Another major difference is that in standard queue your message order won’t be preserve which means the order of the message may be change on some circumstances. But in first in first out queue the message is send and receive in order.Now let’s create a standard queue.

Step 6: After we select the type of queue we need to name our queue. So let’s name our queue “test”. We can use alpha numeric,hyphen and underscore as well.

Step 7: Next we have to configure our queue. In configuration we have visibility timeout, message retention period, delivery delay, maximum message size and receive message wait time. Let us understand this one by one.

Visibility timeout: It is a time period in which only one consumer can access the message in the queue and during this visibility timeout period no other consumer can access the same message. So it can be anything from 0 sec to 12 hours.

Message Retention period: It is the maximum amount of time that a message will be store in the sqs queue before sqs delete it. It can be anything from 1 min to 14 days.

Delivery delay: It is the amount of time to delay the first delivery of each message which means if we give this as 15 sec so only after 15 sec the message will reach the queue.

Maximum message size: the maximum message size depends on the producer who is sending the message.

Receive Message wait time: this is the maximum time that the consumer has to wait in order to pull the message from the queue. It can be anything from 0 to 20 seconds.

Step 8: We will set all our configuration to default and continue with out access policy. Access policy will define who can access your queue. There is two types of method (i) Basic (ii) Advance. Advance uses a json object to define an advance access policy but we will stick to basic for this demo.

Now in this there are options who can send messages to the queue and who can receive message from the queue. There are two options only the queue owner is the person who is creating the queue. Only the queue owner means the person who is creating the queue or you can also specify certain AWS account user or AMI user. The same applies for receive message also.But for this demo we can stick to only the queue owner.

Step 9: Next we have encryption. Encryption is optional. We can encrypt our sensitive data using server-side encryption. Next we have dead letter queue. If a message can’t be consumed successfully you can send it to a dead letter queue.Next we have tag. A tag is a label assigned to the AWS resources. We can use tag to search and filter our resources or track our AWS cost.Now after we have configured and selected the access policy. Let us create a queue.

Step 10: We get a message saying Queue test is created successfully.Now we can see the name of our queue, the type of our queue and the ARN of the queue. It also shows there is no encryption and no dead letter queue.

Step 11: If we click on more.there is more information about the queue. the date it was created, the date it was last updated and what is the maximum message size. It also show the retention period, the default visibility timeout and the message available in the queue.

Now if you scroll down there are various options there is SNS subscription and there is lambda trigger. We can use sqs to trigger any lambda function as well.

Under deadletter queue, we can see that there is no dead letter queue set for this queue.

Under monitoring, we have various graphs such as approximate age of the oldest message, number of message delayed and many more all of these are empty because this is the first queue we have created.

Next we have tags so even this would be empty and this is our access policy then we have no encryption so even this would be empty.

How we can insert a message in SQS queue

Step 1: Now we can click on send and receive message into the queue. So we have the message body. Now let us type a message “Hello”. So this is the message Which I will send to the consumer. Then there is option for delivery delay which is maximum amount of time the message will take to reach the queue. We set it to default which is 0 second.

Step 2: We can also add message attributes. Message attribute can be anything it might be an identifier or a signature or anything else. We will add a message attribute as well. Let us name it demo and value is AWS SQS.

Step 3: when we scroll down we can see the received message. In received message, message available is 0. The polling duration is 30 min and maximum message count is 10. This is default set by AWS SQS.

Now let us send a message. We will get a confirmation that our message is send now if we click on view details. We will have the I’d of the message and md5 of the message body and the message attribute. Md5 is to check if the message send by the producer is the same message which is receive by the consumer.

Now let us check our message. So here we can see the message available is 1. Now let us pull the message from the queue. There are two options to poll the queue.

After the completion of polling, you can see that there is message available over here.When you click on this it will show the body of our message which is Hello. It will also show the attribute which was demo and value was AWS sqs we can also see the details of a message. This is the message id, the size of the message, the md5 of the message body and the message attribute. We can also see the sender account id and what time it send it.his is how you can send and receive message from the queue.

How we can delete a message from the SQS Queue

Step 1: We will just click on the check box and select the delete option.

Step 2: After this it will ask for confirmation if you want to delete the message. We will just click on delete again.

Now we will get a confirmation that one message is deleted successfully.Now you can see that there is no message is available now. This is how message are send and received from the queue.

How we can delete our queue?

Step 1: First we clear the context here and just click on the name of the queue that is test.

Step 2:We have an option to delete our queue. We click on delete and then we have to type delete over here and then click on the delete option over here. We get a confirmation that the name of the queue deleted successfully.

Conclusion:

SQS is a queueing service for message processing. SQS is a system that pull the queue to discover new events so whenever a event is delivered to the queue there is that is nothing going to get involved.

Written by 

I am reliable, hard-working with strong attention to detail and eager to learn about new technologies and business issues. I am able to work well both on my own initiative and as part of a team.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading