Ejemplo n.º 1
0
  public void addSubscription(
      long consumerID,
      String subscriptionID,
      String clientID,
      String durableSubscriptionName,
      String destination,
      String selector,
      String ack)
      throws Exception {
    SimpleString queue = SimpleString.toSimpleString(destination);
    int receiveCredits = consumerCredits;
    if (ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) {
      receiveCredits = -1;
    }

    if (destination.startsWith("jms.topic")) {
      // subscribes to a topic
      if (durableSubscriptionName != null) {
        if (clientID == null) {
          throw BUNDLE.missingClientID();
        }
        queue = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName);
        QueueQueryResult query = session.executeQueueQuery(queue);
        if (!query.isExists()) {
          session.createQueue(
              SimpleString.toSimpleString(destination),
              queue,
              SimpleString.toSimpleString(selector),
              false,
              true);
        }
      } else {
        queue = UUIDGenerator.getInstance().generateSimpleStringUUID();
        session.createQueue(
            SimpleString.toSimpleString(destination),
            queue,
            SimpleString.toSimpleString(selector),
            true,
            false);
      }
      ((ServerSessionImpl) session)
          .createConsumer(consumerID, queue, null, false, false, receiveCredits);
    } else {
      ((ServerSessionImpl) session)
          .createConsumer(
              consumerID,
              queue,
              SimpleString.toSimpleString(selector),
              false,
              false,
              receiveCredits);
    }

    StompSubscription subscription = new StompSubscription(subscriptionID, ack);
    subscriptions.put(consumerID, subscription);

    session.start();
  }