Example usage for javax.jms Session createConsumer

List of usage examples for javax.jms Session createConsumer

Introduction

In this page you can find the example usage for javax.jms Session createConsumer.

Prototype

MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector, boolean noLocal)
        throws JMSException;

Source Link

Document

Creates a MessageConsumer for the specified destination, specifying a message selector and the noLocal parameter.

Usage

From source file:org.apache.axis2.transport.jms.JMSUtils.java

/**
 * This is a JMS spec independent method to create a MessageConsumer. Please be cautious when
 * making any changes// w  ww .ja v  a  2  s .  c  o m
 *
 * @param session JMS session
 * @param destination the Destination
 * @param isQueue is the Destination a queue?
 * @param subscriberName optional client name to use for a durable subscription to a topic
 * @param messageSelector optional message selector
 * @param pubSubNoLocal should we receive messages sent by us during pub-sub?
 * @param isDurable is this a durable topic subscription?
 * @param jmsSpec11 should we use JMS 1.1 API ?
 * @return a MessageConsumer to receive messages
 * @throws JMSException on errors, to be handled and logged by the caller
 */
public static MessageConsumer createConsumer(Session session, Destination destination, Boolean isQueue,
        String subscriberName, String messageSelector, boolean pubSubNoLocal, boolean isDurable,
        boolean jmsSpec11) throws JMSException {

    if (jmsSpec11 || isQueue == null) {
        if (isDurable) {
            return session.createDurableSubscriber((Topic) destination, subscriberName, messageSelector,
                    pubSubNoLocal);
        } else {
            return session.createConsumer(destination, messageSelector, pubSubNoLocal);
        }
    } else {
        if (isQueue) {
            return ((QueueSession) session).createReceiver((Queue) destination, messageSelector);
        } else {
            if (isDurable) {
                return ((TopicSession) session).createDurableSubscriber((Topic) destination, subscriberName,
                        messageSelector, pubSubNoLocal);
            } else {
                return ((TopicSession) session).createSubscriber((Topic) destination, messageSelector,
                        pubSubNoLocal);
            }
        }
    }
}

From source file:org.mule.transport.jms.Jms11Support.java

public MessageConsumer createConsumer(Session session, Destination destination, String messageSelector,
        boolean noLocal, String durableName, boolean topic, ImmutableEndpoint endpoint) throws JMSException {
    if (durableName == null) {
        if (topic) {
            return session.createConsumer(destination, messageSelector, noLocal);
        } else {/*from  www  .ja  va  2  s  .com*/
            return session.createConsumer(destination, messageSelector);
        }
    } else {
        if (topic) {
            return session.createDurableSubscriber((Topic) destination, durableName, messageSelector, noLocal);
        } else {
            throw new JMSException("A durable subscriber name was set but the destination was not a Topic");
        }
    }
}

From source file:org.logicblaze.lingo.jms.JmsServiceExporter.java

/**
 * Factory method to create the consumer
 *//*from www.  j a v a  2 s.c o  m*/
protected MessageConsumer createConsumer() throws JMSException {
    Session session = getResponseRequestor().getSession();
    if (subscriberName != null) {
        if (destination instanceof Topic) {
            Topic topic = (Topic) destination;
            return session.createDurableSubscriber(topic, subscriberName, messageSelector, noLocal);
        } else {
            throw new IllegalArgumentException(
                    "Cannot specify the subscriberName property when using a Queue destination");
        }

    } else {
        return session.createConsumer(destination, messageSelector, noLocal);
    }
}

From source file:org.openadaptor.auxil.connector.jms.JMSReadConnector.java

protected MessageConsumer createMessageConsumerFor(Session connectorSession) {
    if (messageConsumer == null) {
        MessageConsumer newConsumer;/*from  w  w w.  java 2  s .  c  om*/
        if (destination == null) {
            destination = jmsConnection.lookupDestination(getDestinationName());
        }
        try {
            if (durable) {
                newConsumer = connectorSession.createDurableSubscriber((Topic) destination,
                        getDurableSubscriptionName(), getMessageSelector(), isNoLocal());
            } else {
                if (isNoLocal()) { // The value of noLocal only seems to matter if it's true.
                    newConsumer = connectorSession.createConsumer(destination, getMessageSelector(),
                            isNoLocal());
                } else {
                    newConsumer = connectorSession.createConsumer(destination, getMessageSelector());
                }
            }
        } catch (JMSException e) {
            throw new ConnectionException("Unable to subscribe to Destination: [" + getDestinationName() + "]",
                    e, this);
        }
        messageConsumer = newConsumer;
    }
    return messageConsumer;
}

From source file:com.ccc.ccm.client.JMSTemplateAutowired.java

/**
* Create a JMS MessageConsumer for the given Session and Destination.
* <p>This implementation uses JMS 1.1 API.
* @param session the JMS Session to create a MessageConsumer for
* @param destination the JMS Destination to create a MessageConsumer for
* @param messageSelector the message selector for this consumer (can be <code>null</code>)
* @return the new JMS MessageConsumer/*  w  ww . ja va  2 s  .  co m*/
* @throws JMSException if thrown by JMS API methods
*/
protected MessageConsumer createConsumer(Session session, Destination destination, String messageSelector)
        throws JMSException {

    // Only pass in the NoLocal flag in case of a Topic:
    // Some JMS providers, such as WebSphere MQ 6.0, throw IllegalStateException
    // in case of the NoLocal flag being specified for a Queue.
    if (isPubSubDomain()) {
        return session.createConsumer(destination, messageSelector, isPubSubNoLocal());
    } else {
        return session.createConsumer(destination, messageSelector);
    }
}

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

private MessageConsumer getTopicSubscriber(Session session, Topic topic, String selector)
        throws NamingException, JMSException {
    MessageConsumer messageConsumer;/*w ww  . java2 s  .  c  o  m*/
    if (subscriberType.equalsIgnoreCase("DURABLE")) {
        messageConsumer = session.createDurableSubscriber(topic, destinationName, selector, false);
        if (log.isDebugEnabled())
            log.debug("[" + name + "] got durable subscriber for topic [" + destinationName
                    + "] with selector [" + selector + "]");
    } else {
        messageConsumer = session.createConsumer(topic, selector, false);
        if (log.isDebugEnabled())
            log.debug("[" + name + "] got transient subscriber for topic [" + destinationName
                    + "] with selector [" + selector + "]");
    }
    return messageConsumer;
}