How to Receive a Message from the Oracle Messaging Cloud Service with Node.js

const https = require('https');

const req = https.request({ auth: 'username:password', headers: { 'X-OC-ID-TOKEN-STATUS': 'disabled' }, hostname: 'host', method: 'PUT', path: '/service/api/v1/connections/SampleConnection' }, (res) => {

  if (res.statusCode === 201) {
    const cookies = res.headers['set-cookie'];

    const req = https.request({ auth: 'username:password', headers: { cookie: cookies }, hostname: 'host', method: 'PUT', path: '/service/api/v1/sessions/SampleSession?connection=SampleConnection' }, (res) => {

      if (res.statusCode === 201) {
        const req = https.request({ auth: 'username:password', headers: { cookie: cookies }, hostname: 'host', method: 'PUT', path: '/service/api/v1/consumers/SampleConsumer?destination=/queues/SampleQueue&session=SampleSession' }, (res) => {

          if (res.statusCode === 201) {
            const req = https.request({ auth: 'username:password', headers: { cookie: cookies }, hostname: 'host', method: 'POST', path: '/service/api/v1/connections/SampleConnection?action=start' }, (res) => {

              if (res.statusCode === 200) {
                const req = https.request({ auth: 'username:password', headers: { cookie: cookies }, hostname: 'host', method: 'POST', path: '/service/api/v1/consumers/SampleConsumer/messages?timeout=1000' }, (res) => {

                  if (res.statusCode === 200) {
                    var body = '';

                    res.on('data', (chunk) => {
                      body += chunk.toString();
                    });

                    res.on('end', () => {
                      console.log(body);
                    });

                  }

                });

                req.end();
              }

            });

            req.end();
          }

        });

        req.end();
      }

    });

    req.end();
  }

});

req.end();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s