1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.van.business.mq;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -16,7 +17,10 @@ public class MessageProducerService {
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
public void sendMessage(String topic, String message) {
|
||||
this.rocketMQTemplate.convertAndSend(topic, message);
|
||||
private static final String topic = "wx-message";
|
||||
|
||||
|
||||
public void sendMessage(JSONObject jsonObject) {
|
||||
this.rocketMQTemplate.convertAndSend(topic, jsonObject.toJSONString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.van.business.util;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.van.business.enums.WXReqType;
|
||||
import cn.van.business.mq.MessageProducerService;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -63,7 +64,8 @@ public class WXUtil {
|
||||
public static String WX_BASE_URL;
|
||||
private Environment env;
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
private MessageProducerService messageProducerService;
|
||||
|
||||
@Autowired
|
||||
public WXUtil(Environment env) {
|
||||
this.env = env;
|
||||
@@ -101,8 +103,8 @@ public class WXUtil {
|
||||
List<String> strings = splitStringByLength(content, 3072);
|
||||
int count = 1;
|
||||
for (String string : strings) {
|
||||
if (strings.size()>1) {
|
||||
string = "---长消息---第:" + count + "条 "+ "\r" + string ;
|
||||
if (strings.size() > 1) {
|
||||
string = "---长消息---第:" + count + "条 " + "\r" + string;
|
||||
}
|
||||
count++;
|
||||
// 如果是自己的微信,所有信息都加上少爷
|
||||
@@ -140,14 +142,7 @@ public class WXUtil {
|
||||
//wxReqDate.setData(jsonObject);
|
||||
if (Util.isNotEmpty(wxid)) {
|
||||
// 把消息发送到RocketMQ,使用'wx-message'作为topic,jsonObject作为消息内容。
|
||||
rocketMQTemplate.convertAndSend("wx-message", jsonObject);
|
||||
String responseStr = HttpRequest.post(WX_BASE_URL)
|
||||
.body(JSON.toJSONString(jsonObject)).execute().body();
|
||||
if (ObjectUtil.isNotEmpty(responseStr)) {
|
||||
JSONObject response = JSON.parseObject(responseStr);
|
||||
logger.info("消息响应:{}", response.toString());
|
||||
//return response;
|
||||
}
|
||||
messageProducerService.sendMessage(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ rocketmq:
|
||||
name-server: 192.168.8.88:9876 # RocketMQ Name Server 地址
|
||||
producer:
|
||||
group: wx_producer # 生产者组名
|
||||
send-msg-timeout: 3000 # 发送消息超时时间
|
||||
send-msg-timeout: 1000 # 发送消息超时时间
|
||||
consumer:
|
||||
group: wx_consumer # 消费者组名
|
||||
consume-thread-min: 20 # 消费线程池最小线程数
|
||||
|
||||
Reference in New Issue
Block a user