if (!query.isExists())
if (!subResponse.isExists()) if (subResponse.getConsumerCount() > 0) SimpleString oldFilterString = subResponse.getFilterString(); !oldFilterString.equals(coreFilterString); SimpleString oldTopicName = subResponse.getAddress();
if (!query.isExists())
if (!queueQuery.isExists())
public void unsubscribe(final String name) throws JMSException { // As per spec. section 4.11 if (sessionType == HornetQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot unsubscribe using a QueueSession"); } SimpleString queueName = new SimpleString(HornetQDestination.createQueueNameForDurableSubscription(connection.getClientID(), name)); try { QueueQuery response = session.queueQuery(queueName); if (!response.isExists()) { throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name + " does not exist"); } if (response.getConsumerCount() != 0) { throw new IllegalStateException("Cannot unsubscribe durable subscription " + name + " since it has active subscribers"); } session.deleteQueue(queueName); } catch (HornetQException e) { throw JMSExceptionHelper.convertFromHornetQException(e); } }
public void deleteTemporaryQueue(final HornetQDestination tempQueue) throws JMSException { if (!tempQueue.isTemporary()) { throw new InvalidDestinationException("Not a temporary queue " + tempQueue); } try { QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress()); if (!response.isExists()) { throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() + " does not exist"); } if (response.getConsumerCount() > 0) { throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() + " since it has subscribers"); } SimpleString address = tempQueue.getSimpleAddress(); session.deleteQueue(address); connection.removeTemporaryQueue(address); } catch (HornetQException e) { throw JMSExceptionHelper.convertFromHornetQException(e); } }
private boolean subscriptionExists(String subscriptionId) { ClientSession session = null; try { session = sessionFactory.createSession(); ClientSession.QueueQuery query = session.queueQuery(new SimpleString(subscriptionId)); return query.isExists(); } catch (HornetQException e) { throw new RuntimeException(e); } finally { if (session != null) { try { session.close(); } catch (HornetQException e) { } } } }
public void addRegistration(PushTopicRegistration reg) throws Exception { if (reg.isEnabled() == false) return; String destination = reg.getDestination(); ClientSession session = sessionFactory.createSession(false, false, false); ClientSession.QueueQuery query = session.queueQuery(new SimpleString(destination)); ClientSession createSession = null; if (!query.isExists()) { createSession = createSubscription(destination, reg.isDurable()); } PushSubscription consumer = new PushSubscription(sessionFactory, reg.getDestination(), reg.getId(), reg, pushStore); try { consumer.start(); } catch (Exception e) { consumer.stop(); throw new Exception("Failed starting push subscriber for " + destination + " of push subscriber: " + reg.getTarget(), e); } finally { closeSession(createSession); closeSession(session); } consumers.put(reg.getId(), consumer); }
/** * creates IOFog message queues, {@link ClientMessage} producer * and {@link ClientSession} * * @throws Exception */ void initialize() throws Exception { synchronized (messageBusSessionLock) { messageBusSession = sf.createSession(true, true, 0); QueueQuery queueQuery = messageBusSession.queueQuery(new SimpleString(Constants.ADDRESS)); if (queueQuery.isExists()) messageBusSession.deleteQueue(Constants.ADDRESS); queueQuery = messageBusSession.queueQuery(new SimpleString(Constants.COMMAND_LINE_ADDRESS)); if (queueQuery.isExists()) messageBusSession.deleteQueue(Constants.COMMAND_LINE_ADDRESS); messageBusSession.createQueue(Constants.ADDRESS, Constants.ADDRESS, false); messageBusSession.createQueue(Constants.COMMAND_LINE_ADDRESS, Constants.COMMAND_LINE_ADDRESS, false); commandlineProducer = messageBusSession.createProducer(Constants.COMMAND_LINE_ADDRESS); commandlineConsumer = messageBusSession.createConsumer(Constants.COMMAND_LINE_ADDRESS, String.format("receiver = '%s'", "iofog.commandline.command")); commandlineConsumer.setMessageHandler(new CommandLineHandler()); messageBusSession.start(); } }
private HornetQQueue lookupQueue(final String queueName, boolean isTemporary) throws HornetQException { HornetQQueue queue; if (isTemporary) { queue = HornetQDestination.createTemporaryQueue(queueName); } else { queue = HornetQDestination.createQueue(queueName); } QueueQuery response = session.queueQuery(queue.getSimpleAddress()); if (response.isExists()) { return queue; } else { return null; } }
public void deploy(TopicDeployment topicDeployment) throws Exception { if (!started) { throw new Exception("You must start() this class instance before deploying"); } String queueName = topicDeployment.getName(); ClientSession session = sessionFactory.createSession(false, false, false); ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName)); boolean defaultDurable = topicDeployment.isDurableSend(); if (query.isExists()) { defaultDurable = query.isDurable(); } else { session.createQueue(queueName, queueName, topicDeployment.isDurableSend()); } session.close(); destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed()); }
public void deploy(QueueDeployment queueDeployment) throws Exception { if (!started) { throw new Exception("You must start() this class instance before deploying"); } String queueName = queueDeployment.getName(); ClientSession session = sessionFactory.createSession(false, false, false); ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName)); if (!query.isExists()) { session.createQueue(queueName, queueName, queueDeployment.isDurableSend()); } session.close(); destination.createQueueResource(queueName, queueDeployment.isDurableSend(), queueDeployment.getConsumerSessionTimeoutSeconds(), queueDeployment.isDuplicatesAllowed()); }
static boolean queueExists(final String queueName, final ClientSessionFactory sf) throws HornetQException { final ClientSession session = sf.createSession(false, false, false); try { final QueueQuery query = session.queueQuery(new SimpleString(queueName)); return query.isExists(); } finally { session.close(); } }