Receiving Messages

When your device transmits a SBD message, it will be delivered to your Rock7_MO queue. An example is shown below:

{
  "deviceIdentifier": "300234067440860",
  "id": "6vEtxUUXSkSZrypH4GqXCQ",
  "payloadHex": "06154c504e5afd4ad708",
  "timeOfDelivery": "2019-10-28T12:20:10.176Z",
  "vehicle": "IRIDIUM",
  "vehicleMeta": {
    "cdrReference": 575211628,
    "cepRadius": 6,
    "latitude": -27.48612,
    "longitude": 153.23568,
    "momsn": 4813,
    "mtmsn": 0,
    "sessionStatus": "SBD_SESSION_SUCCESSFUL",
    "timeOfSession": "2019-10-28T12:20:09Z",
    "type": "Iridium"
    },
  "version": 1
}

You can receive a message using the SQS console or by integrating with a SDK. Amazon offer first party SDKs for most popular languages, and some languages have support provided by the community.

SQS expects you to receive a message, and then delete it within the Default Visibility Timeout. By default is set to thirty seconds. If your processing could take longer, you should increase this value.

By default, SQS queues retain unacknowledged messages for up to three days. You can increase this up to 14 days by changing the Message Retention Period on the queue.

Sample Code

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.amazonaws.services.sqs.model.Message;

public class SQSDemo {
    private static final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
    public static final String QUEUE_NAME = "Rock7_MO";

    public static void main(String[] args) {
        // Fetch the message
        for (Message message : sqs.receiveMessage(QUEUE_NAME).getMessages()) {
            //Print out the message body
            System.out.println(message.getBody());

            //Let the queue know that the message is processed
            sqs.deleteMessage(QUEUE_NAME, message.getReceiptHandle());
        }
    }
}
import boto3

# Get the service resource
sqs = boto3.resource('sqs')

# Get the queue
queue = sqs.get_queue_by_name(QueueName='Rock7_MO')

# Fetch up to 10 messages
for message in queue.receive_messages():
    # Print out the message body
    print(message.body)

    # Let the queue know that the message is processed
    message.delete()

IAM Permissions

Under the usage described above, an application would need the following permissions in an IAM role:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "sqs:ReceiveMessage",
                "sqs:DeleteMessage"
            ],
            "Resource": "arn:aws:sqs:<YOUR_REGION>:<YOUR_ACCOUNT_ID>:Rock7_MO"
        }
    ]
}

Ensure that you update the account ID to your own account number. If attaching a lambda to your queue, you will also need to add an action of sqs:GetQueueAttributes.