Example usage for javax.jms Session createQueue

List of usage examples for javax.jms Session createQueue

Introduction

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

Prototype

Queue createQueue(String queueName) throws JMSException;

Source Link

Document

Creates a Queue object which encapsulates a specified provider-specific queue name.

Usage

From source file:org.apache.qpid.systest.management.jmx.ConnectionManagementTest.java

public void testProducerFlowBlocked() throws Exception {
    _connection = getConnection();/*from   w w w  .  j  a  v  a2 s .c o m*/
    _connection.start();

    String queueName = getTestQueueName();
    Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
    Queue queue = session.createQueue(queueName);
    createQueueOnBroker(session, queue);

    ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
    managedQueue.setFlowResumeCapacity(DEFAULT_MESSAGE_SIZE * 2l);
    managedQueue.setCapacity(DEFAULT_MESSAGE_SIZE * 3l);

    final ManagedConnection managedConnection = getConnectionMBean();

    // Check that producer flow is not block before test
    final CompositeDataSupport rowBeforeSend = getTheOneChannelRow(managedConnection);
    assertFlowBlocked(rowBeforeSend, false);

    // Check that producer flow does not become block too soon
    sendMessage(session, queue, 3);
    final CompositeDataSupport rowBeforeFull = getTheOneChannelRow(managedConnection);
    assertFlowBlocked(rowBeforeFull, false);

    // Fourth message will over-fill the queue (but as we are not sending more messages, client thread wont't block)
    sendMessage(session, queue, 1);
    final CompositeDataSupport rowAfterFull = getTheOneChannelRow(managedConnection);
    assertFlowBlocked(rowAfterFull, true);

    // Consume two to bring the queue down to the resume capacity
    MessageConsumer consumer = session.createConsumer(queue);
    assertNotNull("Could not receive first message", consumer.receive(1000));
    assertNotNull("Could not receive second message", consumer.receive(1000));
    session.commit();

    // Check that producer flow is no longer blocked
    final CompositeDataSupport rowAfterReceive = getTheOneChannelRow(managedConnection);
    assertFlowBlocked(rowAfterReceive, false);
}

From source file:org.apache.synapse.message.store.impl.jms.JmsStore.java

private Destination getDestination(Session session) {
    Destination dest = queue;//from  www. java 2 s . c  om
    if (dest != null) {
        return dest;
    }
    InitialContext newContext = null;
    try {
        dest = lookup(context, javax.jms.Destination.class, destination);
    } catch (NamingException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(nameString() + ". Could not lookup destination [" + destination + "]. Message: "
                    + e.getLocalizedMessage());
        }
        newContext = newContext();
    }
    try {
        if (newContext != null) {
            dest = lookup(newContext, javax.jms.Destination.class, destination);
        }
    } catch (Throwable t) {
        logger.info(nameString() + ". Destination [" + destination + "] not defined in JNDI context. Message:"
                + t.getLocalizedMessage());
    }
    if (dest == null && session != null) {
        try {
            dest = session.createQueue(destination);
            if (logger.isDebugEnabled()) {
                logger.debug(nameString() + " created destination [" + destination + "] from session object.");
            }
        } catch (JMSException e) {
            logger.error(nameString() + " could not create destination [" + destination + "]. Error:"
                    + e.getLocalizedMessage(), e);
            dest = null;
        }
    }
    if (dest == null && session == null) {
        if (logger.isDebugEnabled()) {
            logger.debug(nameString() + ". Both destination and session is null."
                    + " Could not create destination.");
        }
    }
    synchronized (queueLock) {
        queue = dest;
    }
    return dest;
}

From source file:org.eclipse.smila.connectivity.queue.worker.internal.task.impl.Send.java

/**
 * {@inheritDoc}//  w  w w.  j a v a 2s. c o m
 * 
 */
@Override
public String[] executeInternal(final TaskExecutionEnv env, final SendType config,
        final Map<String, Properties> idPropertyMap)
        throws TaskExecutionException, BlackboardAccessException, RecordFilterNotFoundException {
    Connection connection = null;
    Session session = null;
    try {
        // get cached connection, if do not cache connections -> socket error when many records pushed
        connection = env.getServices().getBrokerConnections().getConnection(config, true);
        connection.start();
        session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        final Destination destination = session.createQueue(config.getQueue());
        final MessageProducer producer = session.createProducer(destination);
        if (config.isPersistentDelivery()) {
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        } else {
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        }

        final Iterator<Entry<String, Properties>> entries = idPropertyMap.entrySet().iterator();
        while (entries.hasNext()) {
            final Entry<String, Properties> entry = entries.next();
            // get message record, optionally a filtered copy.
            final Record record = createMessageRecord(entry.getKey(), config, env);
            // prepare queue message. messages are actually sent on session.commit() below.
            producer.send(createMessage(config, record, entry.getValue(), session));
        }

        // we must commit here so that the message consumer find the correct record version in storages.
        env.getBlackboard().commit();
        env.setCommitRequired(false);
        // finally send the messages.
        session.commit();

        return idPropertyMap.keySet().toArray(new String[idPropertyMap.size()]);
    } catch (final Throwable e) {
        _log.error(msg("Error"), e);
        rollbackQuietly(session);
        throw new TaskExecutionException(e);
    } finally {
        closeQuietly(session);
        closeQuietly(connection);
    }
}

From source file:org.finra.dm.service.helper.DmJmsDestinationResolver.java

@Override
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
        throws JMSException {
    String sqsQueueName = "";
    if (destinationName.equals(SQS_DESTINATION_DM_INCOMING)) {
        sqsQueueName = getIncomingSqsQueueName();
    }//  w w w .j  ava2s.c  om

    Destination destination = null;
    try {
        destination = session.createQueue(sqsQueueName);
    } catch (Exception ex) {
        throw new IllegalStateException(String.format("Failed to resolve the SQS queue: \"%s\".", sqsQueueName),
                ex);
    }
    return destination;
}

From source file:org.finra.herd.service.helper.HerdJmsDestinationResolver.java

@Override
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
        throws JMSException {
    String sqsQueueName;/*w ww.ja v  a2 s . co m*/

    switch (destinationName) {
    case SQS_DESTINATION_HERD_INCOMING:
        // Get the incoming SQS queue name.
        sqsQueueName = getSqsQueueName(ConfigurationValue.HERD_NOTIFICATION_SQS_INCOMING_QUEUE_NAME);
        break;
    case SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE:
        // Get the storage policy selector job SQS queue name.
        sqsQueueName = getSqsQueueName(ConfigurationValue.STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE_NAME);
        break;
    case SQS_DESTINATION_SAMPLE_DATA_QUEUE:
        // Get the storage policy selector job SQS queue name.
        sqsQueueName = getSqsQueueName(ConfigurationValue.SAMPLE_DATA_SQS_QUEUE_NAME);
        break;
    case SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE:
        // Get the storage policy selector job SQS queue name.
        sqsQueueName = getSqsQueueName(ConfigurationValue.SEARCH_INDEX_UPDATE_SQS_QUEUE_NAME);
        break;
    default:
        LOGGER.warn("Failed to resolve the destination name: \"%s\".", destinationName);
        sqsQueueName = "";
        break;
    }

    Destination destination;

    try {
        destination = session.createQueue(sqsQueueName);
    } catch (Exception ex) {
        throw new IllegalStateException(String.format("Failed to resolve the SQS queue: \"%s\".", sqsQueueName),
                ex);
    }

    return destination;
}

From source file:org.mule.transport.jms.integration.AbstractJmsFunctionalTestCase.java

/**
 * By default this will create a Queue, override to create a topic
 *///from w ww . j a  va2s.co m
protected Destination createInputDestination(Session session, Scenario scenario) throws JMSException {
    return session.createQueue(scenario.getInputDestinationName());
}

From source file:org.mule.transport.jms.integration.AbstractJmsFunctionalTestCase.java

/**
 * By default this will create a Queue, override to create a topic
 *///from ww  w  .j av a  2 s. c  om
protected Destination createOutputDestination(Session session, Scenario scenario) throws JMSException {
    return session.createQueue(scenario.getOutputDestinationName());
}

From source file:org.mule.transport.jms.integration.AbstractJmsFunctionalTestCase.java

/**
 * Purge destinations for clean test setup. Especially applicable to WMQ tests, as messages from
 * other tests may still exist from other tests' runs.
 * <p/>//ww w .  j ava2s  .c  o  m
 * Well-behaving tests should drain both inbound and outbound destinations, as well as any intermediary ones.
 * @param destination destination name without any protocol specifics
 */
protected void purge(final String destination) throws JMSException {
    Connection c = null;
    Session s = null;
    try {
        logger.debug("purging queue : " + destination);
        c = getConnection(false, false);
        assertNotNull(c);
        c.start();

        s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination d = s.createQueue(destination);
        MessageConsumer consumer = s.createConsumer(d);

        while (consumer.receiveNoWait() != null) {
            logger.debug("Destination " + destination + " isn't empty, draining it");
        }
    } catch (Exception e) {
        logger.error("unable to purge : " + destination);
    } finally {
        if (c != null) {
            c.stop();
            if (s != null) {
                s.close();
            }
            try {
                c.close();
            } catch (JMSException e) {
                logger.warn("Failed to close jms connection: " + e.getMessage());
            }
        }
    }
}

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

public Destination createDestination(Session session, String name, boolean topic, ImmutableEndpoint endpoint)
        throws JMSException {
    if (connector.isJndiDestinations()) {
        try {/*from w  ww  .  j av a2 s  .  com*/
            Destination dest = getJndiDestination(name);
            if (dest != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            MessageFormat.format("Destination {0} located in JNDI, will use it now", name));
                }
                return dest;
            } else {
                throw new JMSException("JNDI destination not found with name: " + name);
            }
        } catch (JMSException e) {
            if (connector.isForceJndiDestinations()) {
                throw e;
            } else {
                logger.warn("Unable to look up JNDI destination " + name + ": " + e.getMessage());
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Using non-JNDI destination " + name + ", will create one now");
    }

    if (session == null) {
        throw new IllegalArgumentException("Session cannot be null when creating a destination");
    }
    if (name == null) {
        throw new IllegalArgumentException("Destination name cannot be null when creating a destination");
    }

    if (topic) {
        return session.createTopic(name);
    } else {
        return session.createQueue(name);
    }
}

From source file:org.openengsb.ports.jms.JMSPortTest.java

private String sendWithTempQueue(final String msg) {
    String resultString = jmsTemplate.execute(new SessionCallback<String>() {
        @Override//  w  w w. j  a v  a2 s .  c  o m
        public String doInJms(Session session) throws JMSException {
            Queue queue = session.createQueue("receive");
            MessageProducer producer = session.createProducer(queue);
            TemporaryQueue tempQueue = session.createTemporaryQueue();
            MessageConsumer consumer = session.createConsumer(tempQueue);
            TextMessage message = session.createTextMessage(msg);
            message.setJMSReplyTo(tempQueue);
            producer.send(message);
            TextMessage response = (TextMessage) consumer.receive(10000);
            assertThat(
                    "server should set the value of the correltion ID to the value of the received message id",
                    response.getJMSCorrelationID(), is(message.getJMSMessageID()));
            JmsUtils.closeMessageProducer(producer);
            JmsUtils.closeMessageConsumer(consumer);
            return response != null ? response.getText() : null;
        }
    }, true);
    return resultString;
}