public static void main(String[] args) throws Exception {
    CuratorFramework client = null;
    DistributedDelayQueue<String> queue = null;

    try {
      client = CuratorClientFactory.newClient();
      client
          .getCuratorListenable()
          .addListener(
              new CuratorListener() {
                @Override
                public void eventReceived(CuratorFramework client, CuratorEvent event)
                    throws Exception {
                  System.out.println("CuratorEvent: " + event.getType().name());
                }
              });
      client.start();

      QueueConsumer<String> consumer = createQueueConsumer();
      QueueBuilder<String> builder =
          QueueBuilder.builder(client, consumer, createQueueSerializer(), PATH);
      queue = builder.buildDelayQueue();
      queue.start();

      for (int i = 0; i < 10; i++) {
        queue.put("test-" + i, System.currentTimeMillis() + 10000);
      }
      System.out.println(getCurrentTimeStr() + ": 所有的数据已经生产完毕");

      Thread.sleep(20000);
    } finally {
      CloseableUtils.closeQuietly(client);
      CloseableUtils.closeQuietly(queue);
    }
  }
  public <K> void publish(
      QueueConsumer<K> queueConsumer,
      Map<String, String> headers,
      Class<K> clazz,
      K pojo,
      long timeSinceEpoch)
      throws KafkaException {
    QueueItem inner = null;
    try {
      inner = QueueItem.build(mapper, headers, clazz, pojo);
    } catch (IOException e) {
      logger.error("Unable to map/ build queueItem", e);
      throw new KafkaException("Unable to map/ build queueItem", e);
    }

    QueueItem outer = new QueueItem();
    outer.setClassName(this.getClass().getCanonicalName());
    outer.setTryNumber(0);

    outer.setJsonObject(
        Json.createObjectBuilder()
            .add(QUEUE, queueConsumer.queue())
            .add(PAYLOAD, Json.createReader(new StringReader(inner.toString())).read())
            .build());

    logger.debug("queuing delayQ message: {}", outer);
    try {
      delayQ.put(outer.toString(), timeSinceEpoch);
    } catch (Exception e) {
      logger.error("Unable to set timer for delayQ", e);
      throw new KafkaException("Unable to set timer for delayQ", e);
    }
  }
  public DistributedDelayQueue<String> distributedDelayQueue() throws KafkaException {
    org.apache.curator.framework.recipes.queue.QueueConsumer<String> consumer =
        new org.apache.curator.framework.recipes.queue.QueueConsumer<String>() {
          @Override
          public void consumeMessage(String message) {
            logger.debug("message received from delayQ: {}", message);
            JsonObject jsonObject = Json.createReader(new StringReader(message)).readObject();
            String queue = jsonObject.getJsonObject(PAYLOAD).getString(QUEUE);
            String queueMessage =
                jsonObject.getJsonObject(PAYLOAD).getJsonObject(PAYLOAD).toString();
            kafkaClient.sendMessage(new KafkaMessage(queue, queueMessage));
          }

          @Override
          public void stateChanged(CuratorFramework client, ConnectionState newState) {
            if (newState.equals(ConnectionState.SUSPENDED)) {
              logger.error("screwed");
            }
          }
        };

    QueueSerializer<String> serializer =
        new QueueSerializer<String>() {
          @Override
          public byte[] serialize(String item) {
            return item.getBytes(Charset.defaultCharset());
          }

          @Override
          public String deserialize(byte[] bytes) {
            return new String(bytes, Charset.defaultCharset());
          }
        };

    QueueBuilder<String> builder =
        QueueBuilder.builder(curatorFramework, consumer, serializer, DELAY_Q_PATH);

    delayQ = builder.buildDelayQueue();
    try {
      delayQ.start();
    } catch (Exception e) {
      logger.error("unable to start delayQ", e);
      throw new KafkaException("unable to start delayQ", e);
    }

    return delayQ;
  }