예제 #1
0
  /**
   * The failed flag is used here to control delivery count. If set to true the delivery count won't
   * decrement.
   */
  public void amqCloseConsumer(long consumerID, boolean failed) throws Exception {
    final ServerConsumer consumer = consumers.get(consumerID);

    if (consumer != null) {
      consumer.close(failed);
    } else {
      ActiveMQServerLogger.LOGGER.cannotFindConsumer(consumerID);
    }
  }
예제 #2
0
  @Override
  public ServerConsumer createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly,
      final boolean supportLargeMessage,
      final Integer credits)
      throws Exception {
    if (this.internal) {
      // internal sessions doesn't check security

      Binding binding = postOffice.getBinding(queueName);

      if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
      }

      Filter filter = FilterImpl.createFilter(filterString);

      ServerConsumer consumer =
          newConsumer(
              consumerID,
              this,
              (QueueBinding) binding,
              filter,
              started,
              browseOnly,
              storageManager,
              callback,
              preAcknowledge,
              strictUpdateDeliveryCount,
              managementService,
              supportLargeMessage,
              credits);
      consumers.put(consumer.getID(), consumer);

      if (!browseOnly) {
        TypedProperties props = new TypedProperties();

        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

        Queue theQueue = (Queue) binding.getBindable();

        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

        // HORNETQ-946
        props.putSimpleStringProperty(
            ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_REMOTE_ADDRESS,
            SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));

        if (filterString != null) {
          props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }

        Notification notification =
            new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);

        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
          ActiveMQServerLogger.LOGGER.debug(
              "Session with user="******", connection="
                  + this.remotingConnection
                  + " created a consumer on queue "
                  + queueName
                  + ", filter = "
                  + filterString);
        }

        managementService.sendNotification(notification);
      }

      return consumer;
    } else {
      return super.createConsumer(
          consumerID, queueName, filterString, browseOnly, supportLargeMessage, credits);
    }
  }