/** {@inheritDoc} */
  @Override
  public boolean sendMessageToSubscriber(ProtocolMessage protocolMessage, AndesContent content)
      throws AndesException {

    boolean sendSuccess;

    DeliverableAndesMetadata messageMetadata = protocolMessage.getMessage();

    if (messageMetadata.isRetain()) {
      recordRetainedMessage(messageMetadata.getMessageID());
    }

    // Should get the message from the list
    ByteBuffer message = MQTTUtils.getContentFromMetaInformation(content);
    // Will publish the message to the respective queue
    if (null != mqqtServerChannel) {
      try {

        // TODO:review - instead of getSubscribedDestination() used message destination
        mqqtServerChannel.distributeMessageToSubscriber(
            wildcardDestination,
            message,
            messageMetadata.getMessageID(),
            messageMetadata.getQosLevel(),
            messageMetadata.isPersistent(),
            getMqttSubscriptionID(),
            getSubscriberQOS(),
            messageMetadata);

        // We will indicate the ack to the kernel at this stage
        // For MQTT QOS 0 we do not get ack from subscriber, hence will be implicitly creating an
        // ack
        if (QOSLevel.AT_MOST_ONCE.getValue() == getSubscriberQOS()
            || QOSLevel.AT_MOST_ONCE.getValue() == messageMetadata.getQosLevel()) {
          mqqtServerChannel.implicitAck(messageMetadata.getMessageID(), getChannelID());
        }
        sendSuccess = true;
      } catch (MQTTException e) {
        final String error =
            "Error occurred while delivering message to the subscriber for message :"
                + messageMetadata.getMessageID();
        log.error(error, e);
        throw new AndesException(error, e);
      }
    } else {
      sendSuccess = false;
    }

    return sendSuccess;
  }
  /**
   * Return the match between the given two parameters with respect to the protocol.
   *
   * @param wildCardDestination The destination with/without wildcard
   * @param nonWildCardDestination The direct destination without wildcards
   * @return Match status
   * @throws AndesException
   */
  private boolean isMatchForProtocolType(String wildCardDestination, String nonWildCardDestination)
      throws AndesException {
    boolean matching = false;

    if (ProtocolType.AMQP == protocolType) {
      matching =
          AMQPUtils.isTargetQueueBoundByMatchingToRoutingKey(
              wildCardDestination, nonWildCardDestination);
    } else if (ProtocolType.MQTT == protocolType) {
      matching =
          MQTTUtils.isTargetQueueBoundByMatchingToRoutingKey(
              wildCardDestination, nonWildCardDestination);
    } else {
      throw new AndesException("Protocol type " + protocolType + " is not recognized.");
    }

    return matching;
  }