Amazon SQS (aws-sqs
) is an easy queuing service with which you can easily send or receive 1-10 messages at a time. SQS support has been in jclouds since version 1.5.0.
You can lookup a queue by name or create one on demand. Here's a common pattern for that:
URI queue = queueApi.get(queueName);
if (queue == null) {
queue = queueApi.create(queueName);
}
In SQS, once you discover or create a queue, you can focus a connection to to that, by supplying the queue's url.
queueApi = context.getApi().getMessageApiForQueue(queueURI);
Sending a message is simple, just supply the text you wish to send.
queueApi.send("my message");
Receiving a message is also simple: invoke receive
and if your result is not null, you have a message!
message = queueApi.receive();
You can check whether bulk message requests came back, by checking the status result
BatchResult<MessageIdAndMD5> acks = api.send(ImmutableMap.<String, String> builder()
.put("id1", "test message one")
.put("id2", "test message two")
.put("id3", "test message two")
.build());
Note that you can receive the same message twice even in the same request!. Hence we use List, not Set.
List<Message> messages = api.receive(10);