1
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import static cn.hutool.core.thread.ThreadUtil.sleep;
|
||||
import static cn.van.business.util.WXUtil.WX_BASE_URL;
|
||||
|
||||
/**
|
||||
@@ -29,13 +30,13 @@ public class MessageConsumerService implements RocketMQListener<JSONObject> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessageConsumerService.class);
|
||||
|
||||
// create a rate limiter of 1 qps
|
||||
RateLimiter rateLimiter = RateLimiter.create(1.0);
|
||||
RateLimiter rateLimiter = RateLimiter.create(0.5);
|
||||
@Override
|
||||
public void onMessage(JSONObject jsonObject) {
|
||||
// 处理消息
|
||||
try {
|
||||
rateLimiter.acquire(); // 请求许可。如果超过速率,则此方法会阻塞
|
||||
//logger.info("消费到消息:{}", jsonObject);
|
||||
logger.info("消费到消息:{}", jsonObject);
|
||||
String body = jsonObject.getString("body");
|
||||
byte[] decodedBody = Base64.getDecoder().decode(body);
|
||||
String decodedBodyStr = new String(decodedBody, StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user