Example #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);
      }
    }
  }
Example #2
0
  protected void sendSubscriptions() throws Throwable {
    for (DestinationType desType : _consumerList.keySet()) {
      Map<String, BrokerAsyncConsumer> subscriptions = _consumerList.get(desType);
      for (BrokerAsyncConsumer aconsumer : subscriptions.values()) {
        NetSubscribe subscription = aconsumer.getSubscription();

        NetAction netAction = new NetAction(ActionType.SUBSCRIBE);
        netAction.setSubscribeMessage(subscription);

        NetMessage msg = buildMessage(netAction, subscription.getHeaders());

        getNetHandler().sendMessage(msg);
        log.info("Reconnected async consumer for '{}'", subscription.getDestination());
      }
    }
    synchronized (_syncSubscriptions) {
      for (String queueName : _syncSubscriptions.keySet()) {
        getNetHandler().sendMessage(_syncSubscriptions.get(queueName));
      }
    }
  }