Example usage for javax.jms TopicSession createSubscriber

List of usage examples for javax.jms TopicSession createSubscriber

Introduction

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

Prototype


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

Source Link

Document

Creates a nondurable subscriber to the specified topic, using a message selector or specifying whether messages published by its own connection should be delivered to it.

Usage

From source file:org.apache.flink.streaming.connectors.jms.JmsTopicSource.java

@Override
public void run(final SourceContext<T> context) throws Exception {
    TopicSession session = null;
    TopicSubscriber consumer = null;/* w  w w  .j a  va2 s.co  m*/

    try {
        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        consumer = session.createSubscriber(destination, messageSelector, false);

        connection.start();

        while (isRunning) {
            context.collect(convert(consumer.receive()));
        }
    } catch (JMSException e) {
        logger.error("Error receiving message from [{}]: {}", destination.getTopicName(),
                e.getLocalizedMessage());
        throw new UncategorizedJmsException(e);
    } finally {
        JmsUtils.closeMessageConsumer(consumer);
        JmsUtils.closeSession(session);
    }
}

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  w w.  j  a  va2 s  .  co  m*/
    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;/*from ww w.  ja va2 s .c  om*/
    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;
}