Пример #1
0
  /**
   * Pushes a message onto the queue.
   *
   * @param msg The body of the message to push.
   * @param timeout The message's timeout in seconds.
   * @param delay The message's delay in seconds.
   * @param expiresIn The message's expiration offset in seconds.
   * @return The new message's ID
   * @throws HTTPException If the IronMQ service returns a status other than 200 OK.
   * @throws IOException If there is an error accessing the IronMQ server.
   */
  public String push(String msg, long timeout, long delay, long expiresIn) throws IOException {
    Message message = new Message();
    message.setBody(msg);
    message.setTimeout(timeout);
    message.setDelay(delay);
    message.setExpiresIn(expiresIn);

    Messages msgs = new Messages(message);
    Gson gson = new Gson();
    String body = gson.toJson(msgs);

    Reader reader = client.post("queues/" + name + "/messages", body);
    Ids ids = gson.fromJson(reader, Ids.class);
    reader.close();
    return ids.getId(0);
  }
Пример #2
0
 /**
  * Clears the queue off all messages
  *
  * @param queue the name of the queue
  * @throws IOException
  */
 public void clear() throws IOException {
   client.post("queues/" + name + "/clear", "").close();
 }