Пример #1
0
  // amq specific behavior
  public void amqRollback(Set<Long> acked) throws Exception {
    if (tx == null) {
      // Might be null if XA

      tx = newTransaction();
    }

    RefsOperation oper = (RefsOperation) tx.getProperty(TransactionPropertyIndexes.REFS_OPERATION);

    if (oper != null) {
      List<MessageReference> ackRefs = oper.getReferencesToAcknowledge();
      Map<Long, List<MessageReference>> toAcks = new HashMap<Long, List<MessageReference>>();
      for (MessageReference ref : ackRefs) {
        Long consumerId = ref.getConsumerId();

        if (this.consumers.containsKey(consumerId)) {
          if (acked.contains(ref.getMessage().getMessageID())) {
            List<MessageReference> ackList = toAcks.get(consumerId);
            if (ackList == null) {
              ackList = new ArrayList<MessageReference>();
              toAcks.put(consumerId, ackList);
            }
            ackList.add(ref);
          }
        } else {
          // consumer must have been closed, cancel to queue
          ref.getQueue().cancel(tx, ref);
        }
      }
      // iterate consumers
      if (toAcks.size() > 0) {
        Iterator<Entry<Long, List<MessageReference>>> iter = toAcks.entrySet().iterator();
        while (iter.hasNext()) {
          Entry<Long, List<MessageReference>> entry = iter.next();
          ServerConsumer consumer = consumers.get(entry.getKey());
          ((AMQServerConsumer) consumer).amqPutBackToDeliveringList(entry.getValue());
        }
      }
    }

    tx.rollback();

    if (xa) {
      tx = null;
    } else {
      tx = newTransaction();
    }
  }
Пример #2
0
 public void moveToDeadLetterAddress(long consumerId, long mid, Throwable cause) throws Exception {
   AMQServerConsumer consumer = getConsumer(consumerId);
   consumer.moveToDeadLetterAddress(mid, cause);
 }
  public void init() throws Exception {
    AMQServerSession coreSession = session.getCoreSession();

    SimpleString selector =
        info.getSelector() == null ? null : new SimpleString(info.getSelector());

    nativeId = session.getCoreServer().getStorageManager().generateID();

    SimpleString address = new SimpleString(this.actualDest.getPhysicalName());

    if (this.actualDest.isTopic()) {
      String physicalName = this.actualDest.getPhysicalName();
      if (physicalName.contains(".>")) {
        // wildcard
        physicalName = OpenWireUtil.convertWildcard(physicalName);
      }

      // on recreate we don't need to create queues
      address = new SimpleString("jms.topic." + physicalName);
      if (info.isDurable()) {
        subQueueName =
            new SimpleString(
                ActiveMQDestination.createQueueNameForDurableSubscription(
                    true, info.getClientId(), info.getSubscriptionName()));

        QueueQueryResult result = coreSession.executeQueueQuery(subQueueName);
        if (result.isExists()) {
          // Already exists
          if (result.getConsumerCount() > 0) {
            throw new IllegalStateException(
                "Cannot create a subscriber on the durable subscription since it already has subscriber(s)");
          }

          SimpleString oldFilterString = result.getFilterString();

          boolean selectorChanged =
              selector == null && oldFilterString != null
                  || oldFilterString == null && selector != null
                  || oldFilterString != null
                      && selector != null
                      && !oldFilterString.equals(selector);

          SimpleString oldTopicName = result.getAddress();

          boolean topicChanged = !oldTopicName.equals(address);

          if (selectorChanged || topicChanged) {
            // Delete the old durable sub
            coreSession.deleteQueue(subQueueName);

            // Create the new one
            coreSession.createQueue(address, subQueueName, selector, false, true);
          }

        } else {
          coreSession.createQueue(address, subQueueName, selector, false, true);
        }
      } else {
        subQueueName = new SimpleString(UUID.randomUUID().toString());

        coreSession.createQueue(address, subQueueName, selector, true, false);
      }

      coreSession.createConsumer(nativeId, subQueueName, null, info.isBrowser(), false, -1);
    } else {
      SimpleString queueName = new SimpleString("jms.queue." + this.actualDest.getPhysicalName());
      coreSession.createConsumer(nativeId, queueName, selector, info.isBrowser(), false, -1);
    }

    if (info.isBrowser()) {
      AMQServerConsumer coreConsumer = coreSession.getConsumer(nativeId);
      coreConsumer.setBrowserListener(this);
    }
  }