Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with Amazon SQS & SNS in Java

For the first time I have come across Amazon SQS and Amazon SNS. I will be working with these at my work place in Java.

I have a few questions about these,

  1. I don't have that much of Java knowledge, I can't say I have gone that advanced but yes I can say I have an intermediate knowledge. So is it okay for me to touch these areas?

  2. What exactly these services are and how are they useful? A real world example would be useful.

Any suggestions or comments will be useful.

like image 701
user1601973 Avatar asked Sep 13 '12 18:09

user1601973


2 Answers

I wouldn't say you need advanced Java knowledge to use them - but why not try and judge for yourself? The AWS SDK for Java is available at http://aws.amazon.com/sdkforjava/

There's introductory information at http://aws.amazon.com/sns/ and http://aws.amazon.com/sqs/ and links to the detailed documentation.

SQS is useful whenever you need to send reliable, asynchronous messages between parts of a system across the internet. It saves you the effort and expense of setting up your own reliable messaging service, and provides scalability. It is useful when the messages don't have to arrive instantly, but must not go missing. Billing (records of sale) and other non-time-critical financial transactions would be an example. Note that SQS provides "at least once" behaviour - in rare cases it may deliver a message more than once.

SNS is publish-subscribe, rather than queue-based; it is a more consumer-driven style of messaging using topics and subscriptions rather than plain queues. This style is useful when the producer of information may not know all the potential consumers of the information, and their exact needs. See the example applications in the FAQ at http://aws.amazon.com/sns/faqs/#0

like image 78
DNA Avatar answered Oct 05 '22 03:10

DNA


They should be used to support reliable communication between your software components, I think the main question here is why you should split your services in several components / tiers.

I came up with some use cases:

  • long running process that could impact web responsiveness: a most common example is the order processing where payment / credit card charging can be a little bit slow, you create one service that gives the user a quick response, then sends a message to a SQS queue, which triggers a backoffice component that does all the heavy lifting;

  • different scaleability profiles: a common example would a web application where you upload videos and it encodes to several platforms, you might want to create different auto scaling groups with different components, video uploading/browsing (many servers) and video encoding less servers but with higher capacity, the usage would be similar to the previous example.

  • trigger execution of parallel activities: after the order is processed you must send an e-mail to your customer, notify the warehouse to prepare the customs for delivery, tell transport service to pickup the items at the warehouse and deliver at customers address, then you should use a SNS topic where you publish a business event and have 3 components listening that do the following:

    1. Mail Formatting and sending
    2. Warehouse service call
    3. Transport service call

There could be many other usages scenarios, if you tell what your solution needs to do, maybe we could help more preciselly.

like image 44
Alessandro Oliveira Avatar answered Oct 05 '22 02:10

Alessandro Oliveira