1:账号
2:密码
3:MQ地址
4:MQ端口
5:MQ队列名
6:消息内容
附JAVA代码:
package site.duanzy.rabbitMq;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* @author leo
* @date 2022/12/2 15:45
*/
public class RabbitMqTest {
public static void main(String[] args) throws Exception {
String url = "http://root:123456@10.16.2.31:15672/api/exchanges/%2F/amq.default/publish";
List<String> list = new ArrayList<>();
list.add("B088R4H28V");
JSONObject jsonObject = new JSONObject();
jsonObject.put("routing_key", "tsc.asin-info.us.queue");
jsonObject.put("payload_encoding", "string");
jsonObject.put("payload", "leo");
JSONObject properties = new JSONObject();
properties.put("delivery_mode", 1);
JSONObject headers = new JSONObject();
properties.put("headers", headers);
jsonObject.put("properties", properties);
for (String asin : list) {
JSONObject message = new JSONObject();
message.put("asin", asin);
message.put("countryId", 1);
jsonObject.put("payload", message.toJSONString());
String body = jsonObject.toJSONString();
HttpRequest httpRequest = HttpRequest.post(url);
HttpResponse result = httpRequest
.setUrl(url)
.contentLength(body.length())
.header("Host", "10.16.2.31")
.header("Authorization", "Basic cm9vdDoxMjM0NTY=")
.body(body).execute();
System.out.println(result.body()); // 输出:{"routed":true}
}
}
}