Tag Archives: JavaScript

How to Send a Push Notification to AWS SNS with Node.js

const AWS = require('aws-sdk');

AWS.config.update({ credentials: new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'identityPoolId', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey' }), region: 'regionName' });

const sns = new AWS.SNS();

sns.publish({ Message: 'Simples Assim', TopicArn: 'topicArn' }, (err, res) => {});
Advertisements

How to Receive a Message from AWS SQS with Node.js

const AWS = require('aws-sdk');

AWS.config.update({ credentials: new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'identityPoolId', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey' }), region: 'regionName' });

const sqs = new AWS.SQS();

sqs.receiveMessage({ QueueUrl: 'queueUrl' }, (err, res) => {
    console.log(res.Messages[0].Body);

    sqs.deleteMessage({ QueueUrl: 'queueUrl', ReceiptHandle: res.Messages[0].ReceiptHandle }, (err, res) => {});
  });

How to Send a Message to AWS SQS with Node.js

const AWS = require('aws-sdk');

AWS.config.update({ credentials: new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'identityPoolId', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey' }), region: 'regionName' });

const sqs = new AWS.SQS();

sqs.sendMessage({ MessageBody: 'Simples Assim', QueueUrl: 'queueUrl' }, (err, res) => {});

How to Receive a Message from AWS SQS with JavaScript

AWS.config.update({ credentials: new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'identityPoolId', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey' }), region: 'regionName' });

const sqs = new AWS.SQS();

sqs.receiveMessage({ QueueUrl: 'queueUrl' }, (err, res) => {
    console.log(res.Messages[0].Body);

    sqs.deleteMessage({ QueueUrl: 'queueUrl', ReceiptHandle: res.Messages[0].ReceiptHandle }, (err, res) => {});
  });

How to Receive a Message from an Apache ActiveMQ Topic with Node.js

W/o Durability

const stompit = require('stompit');

stompit.connect({ host: 'localhost', port: 61613 }, (err, client) => {
    client.subscribe({ destination: '/topic/SampleTopic' }, (err, msg) => {
        msg.readString('UTF-8', (err, body) => {
            console.log(body);

            client.disconnect();
          });
      });
  });

W/ Durability

const stompit = require('stompit');

stompit.connect({ 'client-id': 'SampleClient', host: 'localhost', port: 61613 }, (err, client) => {
    client.subscribe({ 'activemq.subscriptionName': 'SampleSubscription', destination: '/topic/SampleTopic' }, (err, msg) => {
        msg.readString('UTF-8', (err, body) => {
            console.log(body);

            client.disconnect();
          });
      });
  });