GPS Event [3] – Bus
Now that I have some events flowing — see the previous post — it is time to route them somewhere. I was going to start working on Coral8, but this morning I saw this article on Amazon Simple Queue Service (SQS); so I thought, why not? I always wanted a message bus — hey, everyone should have one; holiday season and all.
Here is what it takes to get a message queue these days:
Step 1 - administer:
- Sign up for an Amazon AWS account.
- Sign up for the SQS service — this is where you need your Visa card.
- Obtain AWS access keys from 'Your Account' menu on the AWS services page.
- Download the Amazon SQS Scratchpad so you can start tinkering immediately.
Step 2 - set it up:
- Start the SQS Scratchpad.
- Enter access keys.
- Select Create Queue from the Explore API list.
- Fill in the Queue Name and leave the Visibility Timeout blank — default is 30seconds.
- Click Invoke Request, the service returns the queue URL — jot this down.
- It takes some time for this request to propagate through AWS, so have a coffee — tea will do too.
Step 3 - tinker:
- Select List Queues from the Explore API list;
- click Invoke Request;
- the service responds with something like this:
<ListQueuesResponse xmlns="http://queue.amazonaws.com/doc/2008-01-01/">
<ListQueuesResult>
<QueueUrl>http://queue.amazonaws.com/EventQueue</QueueUrl>
</ListQueuesResult>
<ResponseMetadata>
<RequestId>02e1a2e9-288f-44f3-9962-08a436cdb1e8</RequestId>
</ResponseMetadata>
</ListQueuesResponse>
And that's it, wasn't bad at all. There is also a nice manual to guide you along the way.
Now you can try writing to and reading from the queue — use the SQS Scratchpad. The Scratchpad exposes the SQS API, so it is possible to manually explore the API commands before one starts programming. Libraries are available for Java, PHP, VB.NET, C#, Perl, Python.
Here are a few things one learns very soon:
- Messages are stored redundantly across several servers — that's nice.
- Maximum number of messages that can be returned in one read is 10.
- If the queue has less than 1000 messages, the read service may actually return less than 10.
- If the queue has only few messages, the read service may return none of them — so the read has to be repeated for service to scan different servers.
- The order of messages is not preserved.
- According to the manual, it is possible to receive a message more than once if all the servers containing the message are not communicating at the time of delete-message operation.
For example — regarding the order of messages — I wrote 10 messages to the queue [Msg 0, Msg 1,..., Msg 9] and read them back.
| Read Attempt | Returned Messages |
|---|---|
| 1 | none |
| 2 | 4, 7 |
| 3 | 5 |
| 4 | 2, 6 |
| 5 | 1 |
| 6 | 0, 3, 8, 9 |
In each read attempt I was asking for 10 messages, the maximum number. Is this good or bad? Depends on the application, I guess.
One more detail, when exploring the SQS Scratchpad use Firefox or IE, Google Chrome does not seem to render XML trees nicely.
Next step is to use Python library and start transferring GPS data to the SQS queue.
To be continued.
Leave a comment