How to Receive a Notification from the Oracle Messaging Cloud Service

REST API w/ Java

W/o Durability

import static java.lang.System.out;

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;

public class OracleCloudSample {

  public static void main(String[] args) {
    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(""));

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

    out.println(res.readEntity(String.class));

    client.close();
  }

}

W/ Durability

import static java.lang.System.out;

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;

public class OracleCloudSample {

  public static void main(String[] args) {
    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(""));

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

    out.println(res.readEntity(String.class));

    client.close();
  }

}

REST API w/ JavaScript

W/o Durability

var 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)) {
    var 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)) {
        var 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)) {
            var 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)) {
                var 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

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

REST API w/ Node.js

W/o Durability

var https = require('https');

var 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) {
    var cookies = res.headers['set-cookie'];

    var 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) {
        var 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) {
            var 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) {
                var 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

var https = require('https');

var 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) {
    var cookies = res.headers['set-cookie'];

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

REST API w/ 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)

Java SDK

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 class OracleCloudSample {

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

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

    ConnectionFactory connFactory = service.getConnectionFactory();

    Connection conn = connFactory.createConnection();

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

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

    MessageConsumer cons = sess.createConsumer(dest);

    conn.start();

    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 class OracleCloudSample {

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

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

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

    Connection conn = connFactory.createConnection();

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

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

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

    conn.start();

    Message msg = cons.receive();

    out.println(msg);

    conn.close();
  }

}
Advertisements

How to Send a Notification to the Oracle Messaging Cloud Service

REST API w/ Java

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;

public class OracleCloudSample {

  public static void main(String[] args) {
    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(""));

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

}

REST API w/ JavaScript

var 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)) {
    var 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)) {
        var 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)) {
            var req = new XMLHttpRequest();

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

            req.send('Simples Assim');
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

REST API w/ Node.js

var https = require('https');

var 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) {
    var cookies = res.headers['set-cookie'];

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

REST API w/ 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')

Java SDK

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 class OracleCloudSample {

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

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

    ConnectionFactory connFactory = service.getConnectionFactory();

    Connection conn = connFactory.createConnection();

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

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

    MessageProducer prod = sess.createProducer(dest);

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

    prod.send(msg);

    conn.close();
  }

}

How to Receive a Message from the Oracle Messaging Cloud Service

REST API w/ Java

import static java.lang.System.out;

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;

public class OracleCloudSample {

  public static void main(String[] args) {
    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(""));

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

    out.println(res.readEntity(String.class));

    client.close();
  }

}

REST API w/ JavaScript

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

REST API w/ Node.js

var https = require('https');

var 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) {
    var cookies = res.headers['set-cookie'];

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

REST API w/ 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)

Java SDK

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 class OracleCloudSample {

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

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

    ConnectionFactory connFactory = service.getConnectionFactory();

    Connection conn = connFactory.createConnection();

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

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

    MessageConsumer cons = sess.createConsumer(dest);

    conn.start();

    Message msg = cons.receive();

    out.println(msg);

    conn.close();
  }

}

How to Send a Message to the Oracle Messaging Cloud Service

REST API w/ Java

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;

public class OracleCloudSample {

  public static void main(String[] args) {
    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(""));

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

}

REST API w/ JavaScript

var 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)) {
    var 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)) {
        var 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)) {
            var req = new XMLHttpRequest();

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

            req.send('Simples Assim');
          }

        };

        req.send();
      }

    };

    req.send();
  }

};

req.send();

REST API w/ Node.js

var https = require('https');

var 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) {
    var cookies = res.headers['set-cookie'];

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

REST API w/ 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')

Java SDK

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 class OracleCloudSample {

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

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

    ConnectionFactory connFactory = service.getConnectionFactory();

    Connection conn = connFactory.createConnection();

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

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

    MessageProducer prod = sess.createProducer(dest);

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

    prod.send(msg);

    conn.close();
  }

}

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