TransitServiceUtils.java
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.cnlive.shenhe.utils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Administrator
*/
@Component
public class TransitServiceUtils {
@Autowired
private AmqpTemplate rabbitTemplate;
/**
* 交换机
*/
private String exchange = "transitService";
/**
* 路由
*/
private String routingKey = "audit";
/**
* MQ 生产者工具类
*
* @param calleeId 接收方 mall 电商 user 用户 daren 达人 cms cms 审核 audit
* @param cmdId 调用URL_ID
* @param isCallback 0需要回调 1不需要回调
* @param data 接口参数
*/
public boolean send(String calleeId, String cmdId, Boolean isCallback, JSONObject data) {
boolean result = true;
try {
JSONObject json = new JSONObject();
json.put("callerId", "audit");
json.put("calleeId", calleeId);
json.put("cmdId", cmdId);
if (isCallback) {
json.put("isCallback", "0");
} else {
json.put("isCallback", "1");
}
json.put("data", data);
this.rabbitTemplate.convertAndSend(exchange, routingKey, json.toString());
} catch (Exception e) {
result = false;
}
return result;
}
}