Last active
March 18, 2018 21:29
-
-
Save jakeceballos/1390aa7001d88ab2f8b43c7cd69534fc to your computer and use it in GitHub Desktop.
Mirth Connect - JS reader for SQS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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