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