How to Receive a Pull Notification from the Oracle Messaging Cloud Service

JAX-RS

W/o Durability

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleOmcsServlet", value = "/")
public final class SampleOmcsServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    Response res = client.target("https://host/service/api/v1/connections/SampleConnection").request().header("X-OC-ID-TOKEN-STATUS", "disabled").put(Entity.json(""));

    final Cookie jsessionid = res.getCookies().get("JSESSIONID");

    client.target("https://host/service/api/v1/sessions/SampleSession").queryParam("connection", "SampleConnection").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/consumers/SampleConsumer").queryParam("destination", "/topics/SampleTopic").queryParam("session", "SampleSession").request().cookie(str).put(Entity.json(""));

    client.target("https://host/service/api/v1/connections/SampleConnection").queryParam("action", "start").request().cookie(jsessionid).post(Entity.json(""));

    res = client.target("https://host/service/api/v1/consumers/SampleConsumer/messages").queryParam("timeout", 1000).request().cookie(jsessionid).post(Entity.json(""));

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

W/ Durability

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleOmcsServlet", value = "/")
public final class SampleOmcsServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    Response res = client.target("https://host/service/api/v1/connections/SampleConnection").request().header("X-OC-ID-TOKEN-STATUS", "disabled").queryParam("clientId", "SampleClient").put(Entity.json(""));

    final Cookie jsessionid = res.getCookies().get("JSESSIONID");

    client.target("https://host/service/api/v1/sessions/SampleSession").queryParam("connection", "SampleConnection").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/consumers/SampleConsumer").queryParam("destination", "/topics/SampleTopic").queryParam("session", "SampleSession").queryParam("subscriptionName", "SampleSubscription").request().cookie(str).put(Entity.json(""));

    client.target("https://host/service/api/v1/connections/SampleConnection").queryParam("action", "start").request().cookie(jsessionid).post(Entity.json(""));

    res = client.target("https://host/service/api/v1/consumers/SampleConsumer/messages").queryParam("timeout", 1000).request().cookie(jsessionid).post(Entity.json(""));

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

Java

W/o Durability

import static java.lang.System.out;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import oracle.cloud.messaging.client.MessagingService;
import oracle.cloud.messaging.client.MessagingServiceCredentials;
import oracle.cloud.messaging.client.MessagingServiceFactory;
import oracle.cloud.messaging.client.MessagingServiceNamespace;

public final class OmcsSample {

  public static void main(final String[] args) throws Exception {
    final MessagingServiceFactory serviceFactory = MessagingServiceFactory.getInstance();

    final MessagingService service = serviceFactory.getMessagingService(new MessagingServiceNamespace("uri"), new MessagingServiceCredentials("username", "password"));

    final ConnectionFactory connFactory = service.getConnectionFactory();

    final Connection conn = connFactory.createConnection();

    final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    final Destination dest = sess.createTopic("SampleTopic");

    final MessageConsumer cons = sess.createConsumer(dest);

    conn.start();

    final Message msg = cons.receive();

    out.println(msg);

    conn.close();
  }

}

W/ Durability

import static java.lang.System.out;
 
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.Topic;

import oracle.cloud.messaging.client.MessagingService;
import oracle.cloud.messaging.client.MessagingServiceCredentials;
import oracle.cloud.messaging.client.MessagingServiceFactory;
import oracle.cloud.messaging.client.MessagingServiceNamespace;

public final class OmcsSample {

  public static void main(final String[] args) throws Exception {
    final MessagingServiceFactory serviceFactory = MessagingServiceFactory.getInstance();

    final MessagingService service = serviceFactory.getMessagingService(new MessagingServiceNamespace("uri"), new MessagingServiceCredentials("username", "password"));

    final ConnectionFactory connFactory = service.getConnectionFactory("SampleClient");

    final Connection conn = connFactory.createConnection();

    final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    final Topic dest = sess.createTopic("SampleTopic");

    final MessageConsumer cons = sess.createDurableSubscriber(dest, "SampleSubscription");

    conn.start();

    final Message msg = cons.receive();

    out.println(msg);

    conn.close();
  }

}

JavaScript

W/o Durability

const req = new XMLHttpRequest();

req.open("PUT", "https://host/service/api/v1/connections/SampleConnection", true, "username", "password");

req.setRequestHeader("X-OC-ID-TOKEN-STATUS", "disabled");

req.onreadystatechange = () => {

  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
    const req = new XMLHttpRequest();

    req.open("PUT", "https://host/service/api/v1/sessions/SampleSession?connection=SampleConnection");

    req.onreadystatechange = () => {

      if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
        const req = new XMLHttpRequest();

        req.open("PUT", "https://host/service/api/v1/consumers/SampleConsumer?destination=/topics/SampleTopic&session=SampleSession");

        req.onreadystatechange = () => {

          if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
            const req = new XMLHttpRequest();

            req.open("POST", "https://host/service/api/v1/connections/SampleConnection?action=start");

            req.onreadystatechange = () => {

              if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200)) {
                const req = new XMLHttpRequest();

                req.open("POST", "https://host/service/api/v1/consumers/SampleConsumer/messages?timeout=1000");

                req.onreadystatechange = () => {

                  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200))
                    console.log(req.responseText);

                };

                req.send();
              }

            };

            req.send();
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

W/ Durability

const req = new XMLHttpRequest();

req.open("PUT", "https://host/service/api/v1/connections/SampleConnection?clientId=SampleClient", true, "username", "password");

req.setRequestHeader("X-OC-ID-TOKEN-STATUS", "disabled");

req.onreadystatechange = () => {

  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
    const req = new XMLHttpRequest();

    req.open("PUT", "https://host/service/api/v1/sessions/SampleSession?connection=SampleConnection");

    req.onreadystatechange = () => {

      if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
        const req = new XMLHttpRequest();

        req.open("PUT", "https://host/service/api/v1/consumers/SampleConsumer?destination=/topics/SampleTopic&session=SampleSession&subscriptionName=SampleSubscription");

        req.onreadystatechange = () => {

          if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
            const req = new XMLHttpRequest();

            req.open("POST", "https://host/service/api/v1/connections/SampleConnection?action=start");

            req.onreadystatechange = () => {

              if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200)) {
                const req = new XMLHttpRequest();

                req.open("POST", "https://host/service/api/v1/consumers/SampleConsumer/messages?timeout=1000");

                req.onreadystatechange = () => {

                  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200))
                    console.log(req.responseText);

                };

                req.send();
              }

            };

            req.send();
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

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) {
                    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();

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) {
                    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();

Python

W/o Durability

import requests

res = requests.put('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), headers={'X-OC-ID-TOKEN-STATUS':'disabled'})

cookies = dict(res.cookies)

requests.put('https://host/service/api/v1/sessions/SampleSession', auth=('username', 'password'), cookies=cookies, params={'connection':'SampleConnection'})

requests.put('https://host/service/api/v1/consumers/SampleConsumer', auth=('username', 'password'), cookies=cookies, params={'destination':'/topics/SampleTopic', 'session':'SampleSession'})

requests.post('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), cookies=cookies, params={'action':'start'})

res = requests.post('https://host/service/api/v1/consumers/SampleConsumer/messages', auth=('username', 'password'), cookies=cookies, params={'timeout':'1000'})

print(res.text)

W/ Durability

import requests

res = requests.put('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), headers={'X-OC-ID-TOKEN-STATUS':'disabled'}, params={'clientId':'SampleClient'})

cookies = dict(res.cookies)

requests.put('https://host/service/api/v1/sessions/SampleSession', auth=('username', 'password'), cookies=cookies, params={'connection':'SampleConnection'})

requests.put('https://host/service/api/v1/consumers/SampleConsumer', auth=('username', 'password'), cookies=cookies, params={'destination':'/topics/SampleTopic', 'session':'SampleSession', 'subscriptionName':'SampleSubscription'})

requests.post('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), cookies=cookies, params={'action':'start'})

res = requests.post('https://host/service/api/v1/consumers/SampleConsumer/messages', auth=('username', 'password'), cookies=cookies, params={'timeout':'1000'})

print(res.text)
Advertisements

How to Send a Pull Notification to the Oracle Messaging Cloud Service

JAX-RS

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleOmcsServlet", value = "/")
public final class SampleOmcsServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://host/service/api/v1/connections/SampleConnection").request().header("X-OC-ID-TOKEN-STATUS", "disabled").put(Entity.json(""));

    final Cookie jsessionid = res.getCookies().get("JSESSIONID");

    client.target("https://host/service/api/v1/sessions/SampleSession").queryParam("connection", "SampleConnection").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/producers/SampleProducer").queryParam("destination", "/topics/SampleTopic").queryParam("session", "SampleSession").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/producers/SampleProducer/messages").request().cookie(jsessionid).post(Entity.json("Simples Assim"));

    client.close();
  }

}

Java

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import oracle.cloud.messaging.client.MessagingService;
import oracle.cloud.messaging.client.MessagingServiceCredentials;
import oracle.cloud.messaging.client.MessagingServiceFactory;
import oracle.cloud.messaging.client.MessagingServiceNamespace;

public final class OmcsSample {

  public static void main(final String[] args) throws Exception {
    final MessagingServiceFactory serviceFactory = MessagingServiceFactory.getInstance();

    final MessagingService service = serviceFactory.getMessagingService(new MessagingServiceNamespace("uri"), new MessagingServiceCredentials("username", "password"));

    final ConnectionFactory connFactory = service.getConnectionFactory();

    final Connection conn = connFactory.createConnection();

    final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    final Destination dest = sess.createTopic("SampleTopic");

    final MessageProducer prod = sess.createProducer(dest);

    final Message msg = sess.createTextMessage("Simples Assim");

    prod.send(msg);

    conn.close();
  }

}

JavaScript

const req = new XMLHttpRequest();

req.open("PUT", "https://host/service/api/v1/connections/SampleConnection", true, "username", "password");

req.setRequestHeader("X-OC-ID-TOKEN-STATUS", "disabled");

req.onreadystatechange = () => {

  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
    const req = new XMLHttpRequest();

    req.open("PUT", "https://host/service/api/v1/sessions/SampleSession?connection=SampleConnection");

    req.onreadystatechange = () => {

      if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
        const req = new XMLHttpRequest();

        req.open("PUT", "https://host/service/api/v1/producers/SampleProducer?destination=/topics/SampleTopic&session=SampleSession");

        req.onreadystatechange = () => {

          if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
            const req = new XMLHttpRequest();

            req.open("POST", "https://host/service/api/v1/producers/SampleProducer/messages");

            req.send('Simples Assim');
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

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/producers/SampleProducer?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/producers/SampleProducer/messages' });

            req.write('Simples Assim');

            req.end();
          }

        });

        req.end();
      }

    });

    req.end();
  }

});

req.end();

Python

import requests

res = requests.put('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), headers={'X-OC-ID-TOKEN-STATUS':'disabled'})

cookies = dict(res.cookies)

requests.put('https://host/service/api/v1/sessions/SampleSession', auth=('username', 'password'), cookies=cookies, params={'connection':'SampleConnection'})

requests.put('https://host/service/api/v1/producers/SampleProducer', auth=('username', 'password'), cookies=cookies, params={'destination':'/topics/SampleTopic', 'session':'SampleSession'})

requests.post('https://host/service/api/v1/producers/SampleProducer/messages', auth=('username', 'password'), cookies=cookies, data='Simples Assim')

How to Receive a Message from the Oracle Messaging Cloud Service

JAX-RS

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleOmcsServlet", value = "/")
public final class SampleOmcsServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    Response res = client.target("https://host/service/api/v1/connections/SampleConnection").request().header("X-OC-ID-TOKEN-STATUS", "disabled").put(Entity.json(""));

    final Cookie jsessionid = res.getCookies().get("JSESSIONID");

    client.target("https://host/service/api/v1/sessions/SampleSession").queryParam("connection", "SampleConnection").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/consumers/SampleConsumer").queryParam("destination", "/queues/SampleQueue").queryParam("session", "SampleSession").request().cookie(str).put(Entity.json(""));

    client.target("https://host/service/api/v1/connections/SampleConnection").queryParam("action", "start").request().cookie(jsessionid).post(Entity.json(""));

    res = client.target("https://host/service/api/v1/consumers/SampleConsumer/messages").queryParam("timeout", 1000).request().cookie(jsessionid).post(Entity.json(""));

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

Java

import static java.lang.System.out;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import oracle.cloud.messaging.client.MessagingService;
import oracle.cloud.messaging.client.MessagingServiceCredentials;
import oracle.cloud.messaging.client.MessagingServiceFactory;
import oracle.cloud.messaging.client.MessagingServiceNamespace;

public final class OmcsSample {

  public static void main(final String[] args) throws Exception {
    final MessagingServiceFactory serviceFactory = MessagingServiceFactory.getInstance();

    final MessagingService service = serviceFactory.getMessagingService(new MessagingServiceNamespace("uri"), new MessagingServiceCredentials("username", "password"));

    final ConnectionFactory connFactory = service.getConnectionFactory();

    final Connection conn = connFactory.createConnection();

    final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    final Destination dest = sess.createQueue("SampleQueue");

    final MessageConsumer cons = sess.createConsumer(dest);

    conn.start();

    final Message msg = cons.receive();

    out.println(msg);

    conn.close();
  }

}

JavaScript

const req = new XMLHttpRequest();

req.open("PUT", "https://host/service/api/v1/connections/SampleConnection", true, "username", "password");

req.setRequestHeader("X-OC-ID-TOKEN-STATUS", "disabled");

req.onreadystatechange = () => {

  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
    const req = new XMLHttpRequest();

    req.open("PUT", "https://host/service/api/v1/sessions/SampleSession?connection=SampleConnection");

    req.onreadystatechange = () => {

      if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
        const req = new XMLHttpRequest();

        req.open("PUT", "https://host/service/api/v1/consumers/SampleConsumer?destination=/queues/SampleQueue&session=SampleSession");

        req.onreadystatechange = () => {

          if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
            const req = new XMLHttpRequest();

            req.open("POST", "https://host/service/api/v1/connections/SampleConnection?action=start");

            req.onreadystatechange = () => {

              if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200)) {
                const req = new XMLHttpRequest();

                req.open("POST", "https://host/service/api/v1/consumers/SampleConsumer/messages?timeout=1000");

                req.onreadystatechange = () => {

                  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 200))
                    console.log(req.responseText);

                };

                req.send();
              }

            };

          req.send();
        }

      };

      req.send();
    }

   };

   req.send();
  }

};

req.send();

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();

Python

import requests

res = requests.put('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), headers={'X-OC-ID-TOKEN-STATUS':'disabled'})

cookies = dict(res.cookies)

requests.put('https://host/service/api/v1/sessions/SampleSession', auth=('username', 'password'), cookies=cookies, params={'connection':'SampleConnection'})

requests.put('https://host/service/api/v1/consumers/SampleConsumer', auth=('username', 'password'), cookies=cookies, params={'destination':'/queues/SampleQueue', 'session':'SampleSession'})

requests.post('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), cookies=cookies, params={'action':'start'})

res = requests.post('https://host/service/api/v1/consumers/SampleConsumer/messages', auth=('username', 'password'), cookies=cookies, params={'timeout':'1000'})

print(res.text)

How to Send a Message to the Oracle Messaging Cloud Service

JAX-RS

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleOmcsServlet", value = "/")
public final class SampleOmcsServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://host/service/api/v1/connections/SampleConnection").request().header("X-OC-ID-TOKEN-STATUS", "disabled").put(Entity.json(""));

    final Cookie jsessionid = res.getCookies().get("JSESSIONID");

    client.target("https://host/service/api/v1/sessions/SampleSession").queryParam("connection", "SampleConnection").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/producers/SampleProducer").queryParam("destination", "/queues/SampleQueue").queryParam("session", "SampleSession").request().cookie(jsessionid).put(Entity.json(""));

    client.target("https://host/service/api/v1/producers/SampleProducer/messages").request().cookie(jsessionid).post(Entity.json("Simples Assim"));

    client.close();
  }

}

Java

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import oracle.cloud.messaging.client.MessagingService;
import oracle.cloud.messaging.client.MessagingServiceCredentials;
import oracle.cloud.messaging.client.MessagingServiceFactory;
import oracle.cloud.messaging.client.MessagingServiceNamespace;

public final class OmcsSample {

  public static void main(final String[] args) throws Exception {
    final MessagingServiceFactory serviceFactory = MessagingServiceFactory.getInstance();

    final MessagingService service = serviceFactory.getMessagingService(new MessagingServiceNamespace("uri"), new MessagingServiceCredentials("username", "password"));

    final ConnectionFactory connFactory = service.getConnectionFactory();

    final Connection conn = connFactory.createConnection();

    final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    final Destination dest = sess.createQueue("SampleQueue");

    final MessageProducer prod = sess.createProducer(dest);

    final Message msg = sess.createTextMessage("Simples Assim");

    prod.send(msg);

    conn.close();
  }

}

JavaScript

const req = new XMLHttpRequest();

req.open("PUT", "https://host/service/api/v1/connections/SampleConnection", true, "username", "password");

req.setRequestHeader("X-OC-ID-TOKEN-STATUS", "disabled");

req.onreadystatechange = () => {

  if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
    const req = new XMLHttpRequest();

    req.open("PUT", "https://host/service/api/v1/sessions/SampleSession?connection=SampleConnection");

    req.onreadystatechange = () => {

      if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
        const req = new XMLHttpRequest();

        req.open("PUT", "https://host/service/api/v1/producers/SampleProducer?destination=/queues/SampleQueue&session=SampleSession");

        req.onreadystatechange = () => {

          if ((req.readyState === XMLHttpRequest.DONE) && (req.status === 201)) {
            const req = new XMLHttpRequest();

            req.open("POST", "https://host/service/api/v1/producers/SampleProducer/messages");

            req.send('Simples Assim');
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

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/producers/SampleProducer?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/producers/SampleProducer/messages' });

            req.write('Simples Assim');

            req.end();
          }

        });

        req.end();
      }

    });

    req.end();
  }

});

req.end();

Python

import requests

res = requests.put('https://host/service/api/v1/connections/SampleConnection', auth=('username', 'password'), headers={'X-OC-ID-TOKEN-STATUS':'disabled'})

cookies = dict(res.cookies)

requests.put('https://host/service/api/v1/sessions/SampleSession', auth=('username', 'password'), cookies=cookies, params={'connection':'SampleConnection'})

requests.put('https://host/service/api/v1/producers/SampleProducer', auth=('username', 'password'), cookies=cookies, params={'destination':'/queues/SampleQueue', 'session':'SampleSession'})

requests.post('https://host/service/api/v1/producers/SampleProducer/messages', auth=('username', 'password'), cookies=cookies, data='Simples Assim')

How to Receive a Message from an Apache ActiveMQ Topic with Ioke

W/o Durability

import javax:jms:Session

import org:apache:activemq:ActiveMQConnectionFactory

connFactory = ActiveMQConnectionFactory new

conn = connFactory createConnection

sess = conn createSession(false, Session field:AUTO_ACKNOWLEDGE)

dest = sess createTopic("SampleTopic")

cons = sess createConsumer(dest)

conn start

msg = cons receive

msg println

conn close

W/ Durability

import javax:jms:Session

import org:apache:activemq:ActiveMQConnectionFactory

connFactory = ActiveMQConnectionFactory new

conn = connFactory createConnection

conn setClientID("SampleClient")

sess = conn createSession(false, Session field:AUTO_ACKNOWLEDGE)

dest = sess createTopic("SampleTopic")

cons = sess createDurableSubscriber(dest, "SampleSubscription")

conn start

msg = cons receive

msg println

conn close

How to Receive a Message from an Apache ActiveMQ Queue with Ioke

import javax:jms:Session

import org:apache:activemq:ActiveMQConnectionFactory

connFactory = ActiveMQConnectionFactory new

conn = connFactory createConnection

sess = conn createSession(false, Session field:AUTO_ACKNOWLEDGE)

dest = sess createQueue("SampleQueue")

cons = sess createConsumer(dest)

conn start

msg = cons receive

msg println

conn close

How to Send a Message to an Apache ActiveMQ Topic with Ioke

import javax:jms:Session

import org:apache:activemq:ActiveMQConnectionFactory

connFactory = ActiveMQConnectionFactory new

conn = connFactory createConnection

sess = conn createSession(false, Session field:AUTO_ACKNOWLEDGE)

dest = sess createTopic("SampleTopic")

prod = sess createProducer(dest)

msg = sess createTextMessage("Simples Assim")

prod send(msg)

conn close

How to Send a Message to an Apache ActiveMQ Queue with Ioke

import javax:jms:Session

import org:apache:activemq:ActiveMQConnectionFactory

connFactory = ActiveMQConnectionFactory new

conn = connFactory createConnection

sess = conn createSession(false, Session field:AUTO_ACKNOWLEDGE)

dest = sess createQueue("SampleQueue")

prod = sess createProducer(dest)

msg = sess createTextMessage("Simples Assim")

prod send(msg)

conn close