Search in sources :

Example 6 with JSONArray

use of com.qcloud.cmq.json.JSONArray in project cmq-java-sdk by tencentyun.

the class Topic method batchPublishMessage.

/**
 * batch publish message
 *
 * @param vMsgList               message array
 * @param vTagList               message tag array
 * @return message handles array
 * @throws Exception
 */
public Vector<String> batchPublishMessage(List<String> vMsgList, List<String> vTagList, String routingKey) throws Exception {
    TreeMap<String, String> param = new TreeMap<String, String>();
    param.put("topicName", this.topicName);
    if (routingKey != null) {
        param.put("routingKey", routingKey);
    }
    if (vMsgList != null) {
        for (int i = 0; i < vMsgList.size(); ++i) {
            param.put("msgBody." + Integer.toString(i + 1), vMsgList.get(i));
        }
    }
    if (vTagList != null) {
        for (int i = 0; i < vTagList.size(); ++i) {
            param.put("msgTag." + Integer.toString(i + 1), vTagList.get(i));
        }
    }
    String result = this.client.call("BatchPublishMessage", param);
    JSONObject jsonObj = new JSONObject(result);
    CMQTool.checkResult(result);
    JSONArray jsonArray = jsonObj.getJSONArray("msgList");
    Vector<String> vmsgId = new Vector<String>();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject obj = (JSONObject) jsonArray.get(i);
        vmsgId.add(obj.getString("msgId"));
    }
    return vmsgId;
}
Also used : JSONObject(com.qcloud.cmq.json.JSONObject) JSONArray(com.qcloud.cmq.json.JSONArray) TreeMap(java.util.TreeMap) Vector(java.util.Vector)

Aggregations

JSONArray (com.qcloud.cmq.json.JSONArray)6 JSONObject (com.qcloud.cmq.json.JSONObject)6 TreeMap (java.util.TreeMap)6 ArrayList (java.util.ArrayList)3 CmqResponse (com.qcloud.cmq.entity.CmqResponse)1 Vector (java.util.Vector)1