Example #1
0
  public void acknowledge(String messageID, String subscriptionID) throws Exception {
    long id = Long.parseLong(messageID);
    Pair<Long, Integer> pair = messagesToAck.remove(id);

    if (pair == null) {
      throw BUNDLE.failToAckMissingID(id);
    }

    long consumerID = pair.getA();
    int credits = pair.getB();

    StompSubscription sub = subscriptions.get(consumerID);

    if (subscriptionID != null) {
      if (!sub.getID().equals(subscriptionID)) {
        throw BUNDLE.subscriptionIDMismatch(subscriptionID, sub.getID());
      }
    }

    if (this.consumerCredits != -1) {
      session.receiveConsumerCredits(consumerID, credits);
    }

    if (sub.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.CLIENT_INDIVIDUAL)) {
      session.individualAcknowledge(consumerID, id);
    } else {
      session.acknowledge(consumerID, id);
    }

    session.commit();
  }
Example #2
0
 boolean containsSubscription(String subscriptionID) {
   Iterator<Entry<Long, StompSubscription>> iterator = subscriptions.entrySet().iterator();
   while (iterator.hasNext()) {
     Map.Entry<Long, StompSubscription> entry = iterator.next();
     StompSubscription sub = entry.getValue();
     if (sub.getID().equals(subscriptionID)) {
       return true;
     }
   }
   return false;
 }
Example #3
0
 public boolean unsubscribe(String id, String durableSubscriptionName) throws Exception {
   Iterator<Entry<Long, StompSubscription>> iterator = subscriptions.entrySet().iterator();
   while (iterator.hasNext()) {
     Map.Entry<Long, StompSubscription> entry = iterator.next();
     long consumerID = entry.getKey();
     StompSubscription sub = entry.getValue();
     if (id != null && id.equals(sub.getID())) {
       iterator.remove();
       session.closeConsumer(consumerID);
       SimpleString queueName;
       if (durableSubscriptionName != null && durableSubscriptionName.trim().length() != 0) {
         queueName = SimpleString.toSimpleString(id + "." + durableSubscriptionName);
       } else {
         queueName = SimpleString.toSimpleString(id);
       }
       QueueQueryResult query = session.executeQueueQuery(queueName);
       if (query.isExists()) {
         session.deleteQueue(queueName);
       }
       return true;
     }
   }
   return false;
 }