|
@@ -1,10 +1,22 @@
|
|
|
package com.caimei365.tools.listener;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.caimei365.tools.model.po.IpSavePo;
|
|
|
+import com.caimei365.tools.service.impl.IpSaveService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.applet.Applet;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
/**
|
|
|
* 测试消息监听
|
|
|
*
|
|
@@ -21,8 +33,45 @@ import org.springframework.stereotype.Component;
|
|
|
// selectorExpression = "tag", // 指定了tag后,发送的消息如果不带tag,将会消费不到
|
|
|
consumerGroup = "Ip_group")
|
|
|
public class IpSaveListener implements RocketMQListener<String> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IpSaveService ipSaveService;
|
|
|
+
|
|
|
@Override
|
|
|
public void onMessage(String message) {
|
|
|
log.info("{}收到消息:{}", this.getClass().getSimpleName(), message);
|
|
|
+ String[] params = message.split("¥");
|
|
|
+ //ip,接口路径,接口参数,注解名
|
|
|
+ String ip=params[0];
|
|
|
+ String path=params[1];
|
|
|
+ String param=params[2];
|
|
|
+ String saveName=params[3];
|
|
|
+ IpSavePo ipSavePo = new IpSavePo();
|
|
|
+ if(StringUtils.isNotBlank(param)){
|
|
|
+ ipSavePo.setParams(param);
|
|
|
+ if(param.contains("userId")){
|
|
|
+ String[] split = param.split("&");
|
|
|
+ for (String s : split) {
|
|
|
+ if(s.contains("userId")&&s.contains("=")){
|
|
|
+ String value = s.split("=")[1];
|
|
|
+ String trim = value.trim();
|
|
|
+ if(StringUtils.isNotBlank(trim)){
|
|
|
+ ipSavePo.setUserId(trim);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(path)){
|
|
|
+ ipSavePo.setRequestUrl(path);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(saveName)){
|
|
|
+ ipSavePo.setPortName(saveName);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(ip)){
|
|
|
+ ipSavePo.setIp(ip);
|
|
|
+ }
|
|
|
+ ipSavePo.setSaveTime(new Date());
|
|
|
+ ipSaveService.save(ipSavePo);
|
|
|
}
|
|
|
}
|