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

W/o Durability

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=/topics/SampleTopic&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)
                              res.on('data', (chunk) => {
                                  console.log(chunk.toString());
                                });

                          });

                        req.end();
                      }

                    });

                  req.end();
                }

              });

            req.end();
          }

        });

      req.end();
    }

  });

req.end();

W/ Durability

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?clientId=SampleClient' }, (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=/topics/SampleTopic&session=SampleSession&subscriptionName=SampleSubscription' }, (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)
                              res.on('data', (chunk) => {
                                  console.log(chunk.toString());
                                });

                          });

                        req.end();
                      }

                    });

                  req.end();
                }

              });

            req.end();
          }

        });

      req.end();
    }

  });

req.end();

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