Skip to content

Martini Invoking Services via an AWS SQS Trigger

Introduction

Amazon Simple Queue Service (AWS SQS) is a fully managed message queuing service offered by Amazon Web Services (AWS) that enables you to decouple and scale microservices, distributed systems, and serverless applications. By integrating AWS SQS with Martini, your packages can seamlessly become part of the AWS ecosystem. This integration allows for the invocation of services in response to SQS events with minimal coding. Martini leverages the AWS SQS SDK's polling API to efficiently retrieve messages from the queue for processing.

Trigger Configuration

To utilize an AWS SQS trigger in Martini, you must configure a trigger with specific settings. Below is an overview of the necessary configuration options for setting up an AWS SQS trigger:

Trigger Type

  • aws-sqs-listener

Trigger Configuration

Configuration Option Required Default Value Description
queueName Yes N/A The name of the AWS SQS queue to be polled.
pollTimeInSeconds No 10 The polling interval in seconds. Adjusting this value can reduce AWS costs by decreasing the frequency of polling requests.
maxNumberOfMessage No 10 The maximum number of messages to be polled in a single request.
awsCredentialOption Yes N/A Determines how AWS credentials are supplied:
- DEFAULT: Uses the default AWS credential provider chain.
- BASIC: Requires specifying AWS credentials directly in the trigger properties.
awsAccessKeyId No N/A Necessary if awsCredentialOption is set to BASIC. This is the AWS Access Key ID.
awsSecretKey No N/A Necessary if awsCredentialOption is set to BASIC. This is the AWS Secret Access Key.
awsSessionToken No N/A Necessary if awsCredentialOption is set to BASIC. This is the AWS session token, applicable for temporary credentials.
messageAttributes Yes N/A Specifies the message attributes to fetch during polling. For multiple attributes, separate them with commas.

Configuration Guide

  1. AWS Credentials: Ensure your AWS credentials are correctly configured. For DEFAULT, confirm the AWS credential provider chain is correctly set up. For BASIC, prepare your awsAccessKeyId, awsSecretKey, and, if applicable, awsSessionToken.

  2. Trigger Configuration: In Martini, create a new AWS SQS trigger and fill in the configuration details as outlined above, tailoring settings to your specific needs.

  3. Define Message Attributes: Determine which message attributes need to be retrieved during polling. Accurate attribute selection is critical for the effective processing of messages within your Gloop services.

  4. Initiate Polling: With the trigger configured, Martini will start polling the specified SQS queue at the intervals you've set. Incoming messages will activate the associated Gloop services for automated message handling.

Best Practices

  • Principle of Least Privilege: Ensure the IAM role or user has only the permissions necessary for operations on the SQS queue to enhance security.
  • Optimize Costs: Modify the pollTimeInSeconds based on your application's requirements. A higher polling interval can reduce costs but might delay message processing.
  • Robust Error Handling: Implement comprehensive error handling within your Gloop services to manage any message processing issues effectively.

Troubleshooting

  • Access Permissions: If there are issues accessing the SQS queue, double-check that the AWS credentials used have the correct permissions.
  • Processing Delays: For delayed message processing, consider decreasing the pollTimeInSeconds or increasing the maxNumberOfMessage to process more messages per polling request.

Trigger Specific Properties

These properties are related to individual messages received from AWS SQS and are essential for processing the messages within Martini.

Name Type Description
queueName String The name of the AWS SQS queue being polled.
messageId String The unique identifier for the message within AWS SQS.
body String The content of the message.
message com.amazonaws.services.sqs.model.Message The complete message object as received from AWS SQS, providing access to all details of the SQS message.
receiptHandle String The message's receipt handle, used for message deletion or change visibility operations.
messageAttributes Array of Pair Model An array of message attributes, each represented as a key-value pair, providing additional information about the message for processing decisions.

Usage and Testing for AWS SQS Trigger in Martini

This section provides a step-by-step guide on how to set up, configure, and test an AWS SQS trigger in Martini. This process involves creating an SQS queue in the AWS Console, setting up a new package in Martini with the necessary configuration, and testing the trigger by sending a message to the queue.

1. Set Up an AWS SQS Queue

  • AWS Console: Go to the AWS Management Console, navigate to the SQS service, and create a new SQS queue. Configure the queue settings according to your requirements.

2. Configure Martini to Use AWS SQS

  • Create a New Package: In Martini, create a new package for your integration.
  • Configure the AWS SQS Trigger: Since a graphical user interface (GUI) for this configuration may not be available yet, you'll need to manually create or edit an XML file to define the AWS SQS trigger. Below is a sample XML configuration for the trigger. Ensure you have the correct AWS credential details and that the AWS SQS has been properly configured in this step.

Sample XML Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<endpoint type="aws-sqs-listener" name="MyEndpoint" service="Test/TestService" enabled="true" modifiable="true">
  <properties>
    <property name="track">false</property>
    <property name="documentType">AWS Sqs Listener</property>
    <property name="replicated">true</property>
    <property name="queueName">ToroQueue</property>
    <property name="pollTimeInSeconds">10</property>
    <property name="maxNumberOfMessage">10</property>
    <property name="awsCredentialOption">BASIC</property>
    <property name="awsRegion">us-east-1</property>
    <property name="awsAccessKeyId">[Your_Access_Key_ID]</property>
    <property name="awsSecretKey">[Your_Secret_Access_Key]</property>
    <property name="awsSessionToken">[Your_Session_Token]</property>
    <property name="messageAttributes">test1,test2</property>
  </properties>
</endpoint>

Note: Replace [Your_Access_Key_ID], [Your_Secret_Access_Key], and [Your_Session_Token] with your actual AWS credentials.

3. Start the Trigger

  • Initiate the Trigger: Start the configured AWS SQS trigger in Martini and ensure it's running properly.

4. Test the Trigger

  • Send a Message: Use the AWS Console to send a message to your SQS queue.
  • Verify Reception: Check if Martini successfully receives the message. You should see the message's properties printed out, confirming that the trigger is correctly processing incoming messages.

5. Observations

  • Message Processing: Upon successful configuration and testing, Martini will automatically receive and process messages sent to the specified AWS SQS queue, demonstrating the trigger's effectiveness in integrating AWS services with Martini's capabilities.