Tag Archives: JMS

How to Receive a Pull Notification from the Oracle Messaging Cloud Service with 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();
  }

}
Advertisements

How to Send a Pull/Push Notification to the Oracle Messaging Cloud Service with 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();
  }

}

How to Receive a Message from the Oracle Messaging Cloud Service with 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();
  }

}

How to Send a Message to the Oracle Messaging Cloud Service with 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();
  }

}

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