Commit 2bb8ccd7 by 韩斌

[20240315007-ZY20240401006]MES端实现设备MQ定向订阅和推送

parent d0945b8b
...@@ -68,7 +68,7 @@ public class MonitorRabbitListener { ...@@ -68,7 +68,7 @@ public class MonitorRabbitListener {
} }
try { try {
String exchangeName = MonitorUtils.getClientExchangeName(deviceId); String exchangeName = MonitorUtils.getClientExchangeName(deviceId);
channel.exchangeDeclare(exchangeName, BuiltinExchangeType.FANOUT, false, true, null); channel.exchangeDeclare(exchangeName, BuiltinExchangeType.FANOUT, false, false, null);
channel.queueDeclare(queueName, true, true, true, null); channel.queueDeclare(queueName, true, true, true, null);
channel.queueBind(queueName, exchangeName, deviceId); channel.queueBind(queueName, exchangeName, deviceId);
} catch (IOException e) { } catch (IOException e) {
......
...@@ -35,7 +35,7 @@ public class MonitorMqttListener { ...@@ -35,7 +35,7 @@ public class MonitorMqttListener {
for (ActiveMQTopic topic : topics) { for (ActiveMQTopic topic : topics) {
if (!mqttListeners.contains(topic.getTopicName())) { if (!mqttListeners.contains(topic.getTopicName())) {
String deviceId = MonitorUtils.getDeviceIdByMqtt(topic.getTopicName()); String deviceId = MonitorUtils.getDeviceIdByMqtt(topic.getTopicName());
channel.exchangeDeclare(MonitorUtils.getClientExchangeName(deviceId), BuiltinExchangeType.FANOUT, false, true, null); channel.exchangeDeclare(MonitorUtils.getClientExchangeName(deviceId), BuiltinExchangeType.FANOUT, false, false, null);
mqttListeners.add(topic.getTopicName()); mqttListeners.add(topic.getTopicName());
//队列等待最多为1,后来的会替换新的 //队列等待最多为1,后来的会替换新的
Destination destination = session.createTopic(topic.getTopicName() + "?consumer.prefetchSize=1"); Destination destination = session.createTopic(topic.getTopicName() + "?consumer.prefetchSize=1");
......
...@@ -2,15 +2,13 @@ package org.gidea.scada.monitor.rabbit.controller; ...@@ -2,15 +2,13 @@ package org.gidea.scada.monitor.rabbit.controller;
import org.gidea.scada.monitor.rabbit.entity.Result; import org.gidea.scada.monitor.rabbit.entity.Result;
import org.gidea.scada.monitor.rabbit.service.MonitorRabbitService; import org.gidea.scada.monitor.rabbit.service.MonitorRabbitService;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
@RestController @RestController
@RequestMapping("/monitor/rabbit") @RequestMapping("/monitor/rabbit")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class MonitorRabbitController { public class MonitorRabbitController {
@Resource @Resource
......
...@@ -18,7 +18,7 @@ public class MonitorRabbitServiceImpl implements MonitorRabbitService { ...@@ -18,7 +18,7 @@ public class MonitorRabbitServiceImpl implements MonitorRabbitService {
@Override @Override
public Result<String> applyConnection(String deviceId) { public Result<String> applyConnection(String deviceId) {
String exchangeName = MonitorUtils.getClientExchangeName(deviceId); String exchangeName = MonitorUtils.getClientExchangeName(deviceId);
FanoutExchange clientExchange = new FanoutExchange(exchangeName, false, true); FanoutExchange clientExchange = new FanoutExchange(exchangeName, false, false);
rabbitAdmin.declareExchange(clientExchange); rabbitAdmin.declareExchange(clientExchange);
return Result.success(exchangeName); return Result.success(exchangeName);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论