Example usage for javax.jms Session unsubscribe

List of usage examples for javax.jms Session unsubscribe

Introduction

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

Prototype


void unsubscribe(String name) throws JMSException;

Source Link

Document

Unsubscribes a durable subscription that has been created by a client.

Usage

From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java

public void tearDownTest() {
    StringBuilder jmsErrorMessages = new StringBuilder();
    int failureCounter = 0;

    for (String subscription : _testSubscriptions.keySet()) {
        Session session = _testSubscriptions.get(subscription);
        try {/*  w  ww .ja v  a 2  s .c  om*/
            session.unsubscribe(subscription);
        } catch (JMSException e) {
            LOGGER.error("Failed to unsubscribe '" + subscription + "' :" + e.getLocalizedMessage(), e);
            failureCounter++;
            appendErrorMessage(jmsErrorMessages, e);
        }
    }

    for (Map.Entry<String, Connection> entry : _testConnections.entrySet()) {
        Connection connection = entry.getValue();
        try {
            connection.close();
        } catch (JMSException e) {
            LOGGER.error("Failed to close connection '" + entry.getKey() + "' :" + e.getLocalizedMessage(), e);
            failureCounter++;
            appendErrorMessage(jmsErrorMessages, e);
        }
    }

    _testConnections.clear();
    _testSubscriptions.clear();
    _testSessions.clear();
    _testProducers.clear();
    _testConsumers.clear();

    if (failureCounter > 0) {
        throw new DistributedTestException("Tear down test encountered " + failureCounter
                + " failures with the following errors: " + jmsErrorMessages.toString());
    }
}

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

/**
 * Clear the specified topic/*from www  .j a  va  2 s .  c  om*/
 */
protected void purgeTopic(String destination, String topic) throws Exception {
    Connection c = null;
    Session s = null;

    try {
        logger.debug("purging topic : " + topic);
        c = getConnection(true, false);
        if (c == null) {
            logger.debug("could not create a connection to topic : " + destination);
        }

        c.start();
        s = ((TopicConnection) c).createTopicSession(true, Session.SESSION_TRANSACTED);

        logger.debug("created topic session");
        Topic dest = s.createTopic(destination);
        logger.debug("created topic destination");

        if (client != null) {
            client.dispose();
        }

        MessageConsumer consumer = null;

        try {
            consumer = s.createDurableSubscriber(dest, topic);
            logger.debug("created consumer");
            while (consumer.receiveNoWait() != null) {
                logger.debug("Topic " + topic + " isn't empty, draining it");
            }
            logger.debug("topic should be empty");
            consumer.close();
            s.unsubscribe(topic);
        } catch (JMSException e) {
            logger.debug("could not unsubscribe : " + topic);
        }
    }

    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());
            }
        }
    }
    logger.debug("completed draining topic :" + topic);
}