Example usage for javax.jms TopicSession createDurableSubscriber

List of usage examples for javax.jms TopicSession createDurableSubscriber

Introduction

In this page you can find the example usage for javax.jms TopicSession createDurableSubscriber.

Prototype

TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal)
        throws JMSException;

Source Link

Document

Creates an unshared durable subscription on the specified topic (if one does not already exist), specifying a message selector and the noLocal parameter, and creates a consumer on that durable subscription.

Usage

From source file:org.aludratest.service.jms.impl.JmsActionImpl.java

@Override
public void subscribeTopic(MessageListener listener, @TechnicalLocator String destinationName,
        @TechnicalArgument String messageSelector, @TechnicalArgument String subscriptionName,
        @TechnicalArgument boolean durable) throws JMSException {
    if (StringUtils.isEmpty(subscriptionName)) {
        throw new IllegalArgumentException("subscriptionName must be provided to subscribe!");
    }//from   w  ww  .j  a v a 2  s .  com
    Topic topic;
    try {
        topic = (Topic) context.lookup(destinationName);
    } catch (NamingException e) {
        throw new AutomationException("Could not lookup destination " + destinationName, e);
    }

    LOGGER.debug("Creating topic-subscriber for topic " + destinationName + " and subscriptionname "
            + subscriptionName);
    Connection c = getDynamicConnection(subscriptionName);

    TopicSession ts = (TopicSession) c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    if (durable) {
        TopicSubscriber subscriber = ts.createDurableSubscriber(topic, subscriptionName, messageSelector,
                false);
        subscriber.setMessageListener(listener);
        this.durableConsumers.put(subscriptionName, subscriber);
    } else {
        ts.createSubscriber(topic, messageSelector, true).setMessageListener(listener);
    }

}

From source file:nl.nn.adapterframework.jms.JMSFacade.java

private TopicSubscriber getTopicSubscriber(TopicSession session, Topic topic, String selector)
        throws NamingException, JMSException {

    TopicSubscriber topicSubscriber;/*  w w  w  .j  ava 2s  .  com*/
    if (subscriberType.equalsIgnoreCase("DURABLE")) {
        topicSubscriber = session.createDurableSubscriber(topic, destinationName, selector, false);
        if (log.isDebugEnabled())
            log.debug("[" + name + "] got durable subscriber for topic [" + destinationName
                    + "] with selector [" + selector + "]");

    } else {
        topicSubscriber = session.createSubscriber(topic, selector, false);
        if (log.isDebugEnabled())
            log.debug("[" + name + "] got transient subscriber for topic [" + destinationName
                    + "] with selector [" + selector + "]");
    }

    return topicSubscriber;
}