Example usage for javax.jms DeliveryMode NON_PERSISTENT

List of usage examples for javax.jms DeliveryMode NON_PERSISTENT

Introduction

In this page you can find the example usage for javax.jms DeliveryMode NON_PERSISTENT.

Prototype

int NON_PERSISTENT

To view the source code for javax.jms DeliveryMode NON_PERSISTENT.

Click Source Link

Document

This is the lowest-overhead delivery mode because it does not require that the message be logged to stable storage.

Usage

From source file:org.dawnsci.commandserver.core.util.JSONUtils.java

/**
 * Generic way of sending a topic notification
 * @param connection - does not get closed afterwards nust be started before.
 * @param message/*from w  w  w  . j ava 2 s .  c  o  m*/
 * @param topicName
 * @param uri
 * @throws Exception
 */
private static final void sendTopic(Connection connection, Object message, String topicName, URI uri)
        throws Exception {

    // JMS messages are sent and received using a Session. We will
    // create here a non-transactional session object. If you want
    // to use transactions you should set the first parameter to 'true'
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    try {
        Topic topic = session.createTopic(topicName);

        MessageProducer producer = session.createProducer(topic);

        final ObjectMapper mapper = new ObjectMapper();

        // Here we are sending the message out to the topic
        TextMessage temp = session.createTextMessage(mapper.writeValueAsString(message));
        producer.send(temp, DeliveryMode.NON_PERSISTENT, 1, 5000);

    } finally {
        session.close();
    }
}

From source file:org.apache.activemq.JmsTopicCompositeSendReceiveTest.java

/**
 * Sets a test to have a queue destination and non-persistent delivery mode.
 *
 * @see junit.framework.TestCase#setUp()
 *//*  w  ww .ja  v  a 2s . c o m*/
protected void setUp() throws Exception {
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    super.setUp();
    consumerDestination2 = consumeSession.createTopic("FOO.BAR.HUMBUG2");
    LOG.info("Created  consumer destination: " + consumerDestination2 + " of type: "
            + consumerDestination2.getClass());
    if (durable) {
        LOG.info("Creating durable consumer");
        consumer2 = consumeSession.createDurableSubscriber((Topic) consumerDestination2, getName());
    } else {
        consumer2 = consumeSession.createConsumer(consumerDestination2);
    }

}

From source file:org.apache.activemq.JmsQueueTopicCompositeSendReceiveTest.java

/**
 * Sets a test to have a queue destination and non-persistent delivery mode.
 *
 * @see junit.framework.TestCase#setUp()
 *//*from  w  w  w .  j a  va 2 s. c o m*/
protected void setUp() throws Exception {
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    topic = false;
    super.setUp();
    consumerDestination2 = consumeSession.createTopic("FOO.BAR.HUMBUG2");
    LOG.info("Created  consumer destination: " + consumerDestination2 + " of type: "
            + consumerDestination2.getClass());
    if (durable) {
        LOG.info("Creating durable consumer");
        consumer2 = consumeSession.createDurableSubscriber((Topic) consumerDestination2, getName());
    } else {
        consumer2 = consumeSession.createConsumer(consumerDestination2);
    }

}

From source file:org.apache.activemq.JmsQueueCompositeSendReceiveTest.java

/**
 * Sets a test to have a queue destination and non-persistent delivery mode.
 *
 * @see junit.framework.TestCase#setUp()
 *//*from w ww. j a va 2  s .c  o  m*/
protected void setUp() throws Exception {
    topic = false;
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    super.setUp();
}

From source file:com.oneops.inductor.MessagePublisher.java

public void init() {
    try {//from w  w w.  jav a  2 s .  c  o  m
        connection = connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination queue = session.createQueue(topic);
        regularProducer = session.createProducer(queue);
        priorityProducer = session.createProducer(queue);
        priorityProducer.setPriority(6);

        if (persistent) {
            regularProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
            priorityProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
        } else {
            regularProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            priorityProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        }
        if (timeToLive != 0) {
            regularProducer.setTimeToLive(timeToLive);
            priorityProducer.setTimeToLive(timeToLive);
        }
    } catch (JMSException e) {
        logger.error(e.getMessage());
        logger.error(e.getMessage(), e);
    }
    super.init();
}

From source file:org.dawnsci.commandserver.core.producer.Broadcaster.java

/**
 * Notify any clients of the beans status
 * @param bean/*from www.j  a va 2s  .co m*/
 * @param add true to add a new message, false to find and update and old one.
 */
public void broadcast(StatusBean bean, boolean add) throws Exception {

    if (connection == null)
        createConnection();
    if (add) {
        addQueue(bean);
    } else {
        updateQueue(bean); // For clients connecting in future or after a refresh - persistence.
    }

    final ObjectMapper mapper = new ObjectMapper();

    // Here we are sending the message out to the topic
    TextMessage temp = session.createTextMessage(mapper.writeValueAsString(bean));
    topicProducer.send(temp, DeliveryMode.NON_PERSISTENT, 1, 5000);

    if (out != null) {
        out.println(bean.toString());
        out.flush();
    }

    if (bean.getStatus().isFinal()) { // No more updates!
        dispose();
    }

}

From source file:net.blogracy.services.StoreService.java

public StoreService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {/*from ww  w.  j  a va  2  s  .  c o  m*/
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("store");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating store service");
    }
}

From source file:net.blogracy.services.SeedService.java

public SeedService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {//from  w ww.  j a v  a2 s.  co  m
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("seed");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating seed service");
    }
}

From source file:biz.fstechnology.micro.server.jms.AbstractJmsService.java

/**
 * @see biz.fstechnology.micro.server.Service#init()
 *///from  ww w. j  a v a2s  .  co m
@Override
public void init() throws Exception {
    Connection connection = createJmsTemplate().getConnectionFactory().createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createTopic(getListenTopic()));
    consumer.setMessageListener(this);

    replyProducer = session.createProducer(null);
    replyProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    connection.start();
}

From source file:TopicPublisher.java

private void run() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
    connection = factory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    topic = session.createTopic("topictest.messages");
    control = session.createTopic("topictest.control");

    publisher = session.createProducer(topic);
    publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    payload = new byte[size];
    for (int i = 0; i < size; i++) {
        payload[i] = (byte) DATA[i % DATA.length];
    }/*from ww  w  .  j av a 2s.c o m*/

    session.createConsumer(control).setMessageListener(this);
    connection.start();

    long[] times = new long[batch];
    for (int i = 0; i < batch; i++) {
        if (i > 0) {
            Thread.sleep(delay * 1000);
        }
        times[i] = batch(messages);
        System.out.println("Batch " + (i + 1) + " of " + batch + " completed in " + times[i] + " ms.");
    }

    long min = min(times);
    long max = max(times);
    System.out.println("min: " + min + ", max: " + max + " avg: " + avg(times, min, max));

    // request shutdown
    publisher.send(session.createTextMessage("SHUTDOWN"));

    connection.stop();
    connection.close();
}