Esempio n. 1
0
  protected void notifyListener(NetNotification notification) {
    Map<String, String> headers = notification.getHeaders();
    boolean ackRequired = true;
    if (headers != null) {
      String value = headers.get("ACK_REQUIRED");
      if (value != null) {
        if (value.equalsIgnoreCase("false")) {
          ackRequired = false; // ACK is not required
        }
      }
    }

    Map<String, BrokerAsyncConsumer> subscripions =
        _consumerList.get(
            notification.getDestinationType().equals(DestinationType.TOPIC)
                ? DestinationType.TOPIC
                : DestinationType.QUEUE);

    BrokerAsyncConsumer brokerAsyncConsumer = subscripions.get(notification.getSubscription());

    if (brokerAsyncConsumer == null) {
      log.error(
          String.format(
              "Unexpected notification. DestinationType: %s, Destination: %s, Subscription: %s.",
              notification.getDestinationType(),
              notification.getDestination(),
              notification.getSubscription()));
      return;
    }
    brokerAsyncConsumer.deliver(notification);

    BrokerListener listener = brokerAsyncConsumer.getListener();

    if (!ackRequired) {
      return;
    }

    if ((notification.getDestinationType() != DestinationType.TOPIC) && listener.isAutoAck()) {
      try {
        acknowledge(notification);
      } catch (Throwable t) {
        log.error(
            "Could not acknowledge message, messageId: '{}'",
            notification.getMessage().getMessageId());
        log.error(t.getMessage(), t);
      }
    }
  }