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;
}
Aggregations