@Override @After public void tearDown() throws Exception { if (jmsMgr != null) { jmsMgr.close(); } }
/** Creates topics and queues and starts listeners */ private void createDestinations() throws MessagingException { try { // Create Destinations based on properties Enumeration<?> propertyNames = m_connectionProperties.keys(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); if (propertyName.startsWith("topic.")) { String destinationName = m_connectionProperties.getProperty(propertyName); m_jmsManager.createDestination(destinationName, DestinationType.Topic); } else if (propertyName.startsWith("queue.")) { String destinationName = m_connectionProperties.getProperty(propertyName); m_jmsManager.createDestination(destinationName, DestinationType.Queue); } } // Get destination list List<Destination> destinations = m_jmsManager.getDestinations(); // If there are no Destinations, throw an exception if (destinations.size() == 0) { throw new MessagingException( "No destinations available for " + "subscription, make sure that there is at least one topic " + "or queue specified in the connection properties."); } // Subscribe for (Destination destination : destinations) { if (m_durable && destination instanceof Topic) { m_jmsManager.listenDurable((Topic) destination, m_messageSelector, this, null); } else { m_jmsManager.listen(destination, m_messageSelector, this); } } } catch (MessagingException me) { logger.error( "MessagingException encountered attempting to start " + "Messaging Client: " + m_clientId + ". Exception message: " + me.getMessage(), me); throw me; } }
/** * Stops the MessagingClient, shuts down connections. If the unsubscribe parameter is set to true, * all durable subscriptions will be removed. * * @param unsubscribe */ public void stop(boolean unsubscribe) throws MessagingException { try { if (unsubscribe) { m_jmsManager.unsubscribeAllDurable(); } m_jmsManager.close(); m_jmsManager = null; m_connected = false; } catch (MessagingException me) { logger.error( "Messaging Exception encountered attempting to stop " + "Messaging Client: " + m_clientId + ". Exception message: " + me.getMessage(), me); throw me; } }