@Override
  public boolean hasCredits(ServerConsumer consumer) {
    ProtonPlugSender plugSender = (ProtonPlugSender) consumer.getProtocolContext();

    if (plugSender != null && plugSender.getSender().getCredit() > 0) {
      return true;
    } else {
      return false;
    }
  }
  @Override
  public int sendMessage(ServerMessage message, ServerConsumer consumer, int deliveryCount) {

    ProtonPlugSender plugSender = (ProtonPlugSender) consumer.getProtocolContext();

    try {
      return plugSender.deliverMessage(message, deliveryCount);
    } catch (Exception e) {
      synchronized (connection.getLock()) {
        plugSender
            .getSender()
            .setCondition(new ErrorCondition(AmqpError.INTERNAL_ERROR, e.getMessage()));
        connection.flush();
      }
      throw new IllegalStateException("Can't deliver message " + e, e);
    }
  }