feat():RabbitMq监听信息
parent
05d11caa6b
commit
c8591c3fd6
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -1,4 +1,4 @@
|
||||||
package com.zhiLian.common.req;
|
package com.zhiLian.common;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -0,0 +1,136 @@
|
||||||
|
//package com.zhiLian.config;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import com.alibaba.fastjson2.JSON;
|
||||||
|
//import com.alibaba.fastjson2.JSONArray;
|
||||||
|
//import com.alibaba.fastjson2.JSONObject;
|
||||||
|
//import com.aliyun.ecs20140526.Client;
|
||||||
|
//import com.zhiLian.common.ConnectWeight;
|
||||||
|
//import com.zhiLian.service.impl.LoadBalanceServiceImpl;
|
||||||
|
//import com.zhiLian.utils.ECSTool;
|
||||||
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.boot.ApplicationArguments;
|
||||||
|
//import org.springframework.boot.ApplicationRunner;
|
||||||
|
//import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
//import org.springframework.http.*;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//import org.springframework.web.client.RestTemplate;
|
||||||
|
//
|
||||||
|
//import java.math.BigDecimal;
|
||||||
|
//import java.math.RoundingMode;
|
||||||
|
//import java.util.*;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 初始化连接权重
|
||||||
|
// *
|
||||||
|
// * @author YouChe·He
|
||||||
|
// * @ClassName: InitConnectWeight
|
||||||
|
// * @Description: 初始化连接权重
|
||||||
|
// * @CreateTime: 2024/5/27 21:31
|
||||||
|
// */
|
||||||
|
//@Component
|
||||||
|
//@Slf4j
|
||||||
|
//public class InitConnectWeight implements ApplicationRunner {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private RedisTemplate<String, String> redisTemplate;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private RestTemplate restTemplate;
|
||||||
|
// @Autowired
|
||||||
|
// private LoadBalanceServiceImpl loadBalanceServiceimpl;
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void run(ApplicationArguments args) throws Exception {
|
||||||
|
//
|
||||||
|
// ArrayList<ConnectWeight> connectWeightList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Client client = null;
|
||||||
|
// //获取阿里云客户端
|
||||||
|
// try {
|
||||||
|
// client = ECSTool.createClient();
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
// //获取所有实例
|
||||||
|
// List< String > ipList = ECSTool.FindInstance ( "cn-zhangjiakou" );
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //http://fluxmq.muyu.icu/public/login
|
||||||
|
//
|
||||||
|
// //遍历所有ip,获取每一个服务的连接数
|
||||||
|
// for (String ip : ipList) {
|
||||||
|
// String url = "http://" + ip + ":8080/public/login";
|
||||||
|
// Map<String, Object> request = new HashMap<>();
|
||||||
|
// request.put("username", "fluxmq");
|
||||||
|
// request.put("password", "fluxmq");
|
||||||
|
// HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
// httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
// HttpEntity<Map<String, Object>> r = new HttpEntity<Map<String, Object>>(request, httpHeaders);
|
||||||
|
// String result = restTemplate.postForObject(url, r, String.class);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //http://fluxmq.muyu.icu/public/cluster
|
||||||
|
//
|
||||||
|
// int nextInt = new Random().nextInt(1000);
|
||||||
|
// String getInfoUrl = "http://" + ip + ":8080/public/cluster?random=" + nextInt;
|
||||||
|
//
|
||||||
|
// HttpHeaders httpHeadersGetInfo = new HttpHeaders();
|
||||||
|
// httpHeadersGetInfo.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
// httpHeadersGetInfo.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
|
// httpHeadersGetInfo.set("Cookie", result);
|
||||||
|
// HttpEntity getInfoRequest = new HttpEntity(httpHeadersGetInfo);
|
||||||
|
// ResponseEntity<String> responseInfo = restTemplate.exchange(getInfoUrl, HttpMethod.GET, getInfoRequest, String.class, 1);
|
||||||
|
//
|
||||||
|
// log.error("响应是:{}", responseInfo.getBody());
|
||||||
|
//
|
||||||
|
// JSONArray jsonArray = JSON.parseArray(responseInfo.getBody());
|
||||||
|
// if (jsonArray.size() > 0) {
|
||||||
|
//
|
||||||
|
// JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
|
// Integer connectSize = Integer.valueOf(jsonObject.getJSONObject("mqttInfo").getString("connectSize"));
|
||||||
|
// connectWeightList.add(new ConnectWeight(ip,100-connectSize));
|
||||||
|
// log.error("链接数量:{}", connectSize);
|
||||||
|
// } else {
|
||||||
|
// log.error("得到的相应数据为null");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Integer sum =0;
|
||||||
|
// for (ConnectWeight connectWeight : connectWeightList) {
|
||||||
|
// sum = sum + connectWeight.getWeightValue();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// int max = 0;
|
||||||
|
// for (ConnectWeight connectWeight : connectWeightList) {
|
||||||
|
// log.error("权重值:{}",connectWeight.getWeightValue());
|
||||||
|
// Integer result = BigDecimal.valueOf(connectWeight.getWeightValue() * 100).divide(BigDecimal.valueOf(sum), 0, RoundingMode.DOWN).intValue();
|
||||||
|
// if (result > max){
|
||||||
|
// max = result;
|
||||||
|
// }
|
||||||
|
// connectWeight.setWeightValue(result);
|
||||||
|
// log.error("100次轮询次数:{}",result);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ArrayList<String> weightIpList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// //轮询出现次数
|
||||||
|
// for (int i = 0; i <= max; i++) {
|
||||||
|
// for (ConnectWeight connectWeight : connectWeightList) {
|
||||||
|
// if (connectWeight.getWeightValue() > i){
|
||||||
|
// weightIpList.add(connectWeight.getCarServerIp());
|
||||||
|
// }else if (connectWeight.getWeightValue() == max){
|
||||||
|
// weightIpList.add(connectWeight.getCarServerIp());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //存入redis
|
||||||
|
// redisTemplate.delete("ipList");
|
||||||
|
// for (String ip : weightIpList) {
|
||||||
|
// redisTemplate.opsForList().rightPush("ipList",ip);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.zhiLian.consumer;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReceiveHandler
|
||||||
|
* @Description 描述
|
||||||
|
* @Author YunFei.Du
|
||||||
|
* @Date 2024/5/29 20:08
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class ReceiveHandler {
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
// test
|
||||||
|
@RabbitListener(queues = {"ADD_LOG_AAA"})
|
||||||
|
public void addLog(String msg) {
|
||||||
|
log.info("接收到消息:{}", msg);
|
||||||
|
redisTemplate.opsForList().leftPush("log", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RabbitListener(queues = {"test"})
|
||||||
|
public void receiveSms(Message message) {
|
||||||
|
log.info("接收到消息:{}", message);
|
||||||
|
redisTemplate.opsForList().leftPush("log", message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.zhiLian.common.Result;
|
import com.zhiLian.common.Result;
|
||||||
import com.zhiLian.common.req.ConnectWeight;
|
import com.zhiLian.common.ConnectWeight;
|
||||||
import com.zhiLian.service.LoadBalanceService;
|
import com.zhiLian.service.LoadBalanceService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
package com.zhiLian.utils;
|
package com.zhiLian.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.aliyun.ecs20140526.Client;
|
import com.aliyun.ecs20140526.Client;
|
||||||
import com.aliyun.ecs20140526.models.*;
|
import com.aliyun.ecs20140526.models.*;
|
||||||
import com.aliyun.tea.TeaException;
|
import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.tea.TeaModel;
|
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.aliyun.teautil.Common;
|
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
import com.zhiLian.common.req.ConnectWeight;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.http.*;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
|
@ -140,7 +130,12 @@ public class ECSTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例列表
|
||||||
|
* @param regionId
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public static List<String> FindInstance( String regionId) throws Exception {
|
public static List<String> FindInstance( String regionId) throws Exception {
|
||||||
// 创建ECS客户端
|
// 创建ECS客户端
|
||||||
Client client = ECSTool.createClient ( );
|
Client client = ECSTool.createClient ( );
|
||||||
|
|
Loading…
Reference in New Issue