Skip to content

Instantly share code, notes, and snippets.

@jakeceballos
Last active March 18, 2018 21:29
Show Gist options
  • Save jakeceballos/1390aa7001d88ab2f8b43c7cd69534fc to your computer and use it in GitHub Desktop.
Save jakeceballos/1390aa7001d88ab2f8b43c7cd69534fc to your computer and use it in GitHub Desktop.
Mirth Connect - JS reader for SQS
/*
Prequisites:
* Mirth is running on instance with IAM Role
* IAM Role has permissions to SQS
*/
var queueURL = 'https://sqs.us-east-1.amazonaws.com/776306751262/wiz_inbound_json_dev.fifo';
var request = com.amazonaws.services.sqs.model.ReceiveMessageRequest()
.withQueueUrl(queueURL)
.withMaxNumberOfMessages(10)
.withMessageAttributeNames(['All']);
var client = new com.amazonaws.services.sqs.AmazonSQSClientBuilder.standard()
.withCredentials(new Packages.com.amazonaws.auth.InstanceProfileCredentialsProvider(false))
.build();
var messageList = client.receiveMessage(request).getMessages();
if (messageList.isEmpty()) return null;
var messages = new java.util.ArrayList();
for each(obj in messageList.toArray()) {
// Process all messages, ignoring those that fail to do so
try {
var map = java.util.HashMap();
var messageAttributes = obj.getMessageAttributes();
var target = messageAttributes.get('target').getStringValue();
var type = messageAttributes.get('type').getStringValue();
map.put('target', target);
map.put('type', type);
var rawMessage = new RawMessage(obj.getBody(), null, map);
messages.add(rawMessage);
client.deleteMessage(queueURL, obj.getReceiptHandle());
} catch (err) {
// Do something
}
}
return messages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment