Permalink
Browse files

Use new, batch message style API

The old style is deprecated.
  • Loading branch information...
1 parent 834add8 commit 7920051ec554077c6f64bc34bacc52591b8aaa65 Evan Shaw committed Feb 2, 2012
Showing with 16 additions and 6 deletions.
  1. +16 −6 src/main/java/io/iron/ironmq/Queue.java
@@ -2,6 +2,8 @@
import java.io.IOException;
+import net.sf.json.JSON;
+import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
@@ -26,11 +28,14 @@
*/
public Message get() throws IOException {
JSONObject jsonObj = client.get("queues/" + name + "/messages");
+ JSONArray array = jsonObj.getJSONArray("messages");
+ JSONObject jsonMsg = array.getJSONObject(0);
+
Message msg = new Message();
- msg.setId((String)jsonObj.get("id"));
- msg.setBody(jsonObj.getString("body"));
- if (jsonObj.has("timeout")) {
- msg.setTimeout(jsonObj.getLong("timeout"));
+ msg.setId(jsonMsg.getString("id"));
+ msg.setBody(jsonMsg.getString("body"));
+ if (jsonMsg.has("timeout")) {
+ msg.setTimeout(jsonMsg.getLong("timeout"));
}
return msg;
}
@@ -84,7 +89,12 @@ public void push(String msg, long timeout) throws IOException {
Message message = new Message();
message.setBody(msg);
message.setTimeout(timeout);
- String jsonStr = JSONSerializer.toJSON(message).toString();
- client.post("queues/" + name + "/messages", jsonStr);
+
+ JSON jsonMsg = JSONSerializer.toJSON(message);
+ JSONArray array = new JSONArray();
+ array.add(jsonMsg);
+ JSONObject outer = new JSONObject();
+ outer.element("messages", array);
+ client.post("queues/" + name + "/messages", outer.toString());
}
}

0 comments on commit 7920051

Please sign in to comment.