diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java new file mode 100644 index 0000000..0ac19d4 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.alarm.monitor.listener; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.Message; +import org.springframework.data.redis.connection.MessageListener; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.stereotype.Component; + +/** + * @author ysj + * @version 4.0.0 + * @create 2023-11-09-14:04 + */ +@Component +public class AlarmListener implements MessageListener { + + @Autowired + private RedisTemplate redisTemplate; + + @Override + public void onMessage(Message message, byte[] pattern) { + RedisSerializer serializer = redisTemplate.getStringSerializer(); + String msg = serializer.deserialize(message.getBody()); + System.out.println("接收到的消息是:" + msg); + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java new file mode 100644 index 0000000..418df54 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.alarm.monitor.listener; + +import com.hnac.hzims.common.config.RedisMessageListener; +import org.springframework.context.annotation.Bean; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.PatternTopic; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; + +/** + * @author ysj + * @version 4.0.0 + * @create 2023-11-09 14:02 + */ +public class QuqueConfig { + + + /** + * 创建连接工厂 + * + * @param connectionFactory + * @param adapter + * @return + */ + @Bean + public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, + MessageListenerAdapter adapter) { + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + container.setConnectionFactory(connectionFactory); + //监听对应的channel + container.addMessageListener(adapter, new PatternTopic("alarmchannel")); + return container; + } + + /** + * 绑定消息监听者和接收监听的方法 + * @param message + * @return + */ + @Bean + public MessageListenerAdapter adapter(RedisMessageListener message) { + // onMessage 如果RedisMessage 中 没有实现接口,这个参数必须跟RedisMessage中的读取信息的方法名称一样 + return new MessageListenerAdapter(message, "onMessage"); + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java new file mode 100644 index 0000000..8bf2fa0 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java @@ -0,0 +1,8 @@ +package com.hnac.hzims.alarm.monitor.service; + +/** + * @author ysj + */ +public interface AlarmSaveService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java new file mode 100644 index 0000000..0472496 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.monitor.service.impl; + +import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@AllArgsConstructor +@Service +@Slf4j +public class AlarmSaveServiceImpl implements AlarmSaveService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java index 3c9eb67..66da6fe 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java @@ -48,7 +48,7 @@ public class ShowAlarmController extends BladeController { @PostMapping("/show") @ApiOperationSupport(order = 2) @ApiOperation(value = "告警列表分页", notes = "传入: AlarmConfigEntity对象,分页参数") - public R> alarms(@ApiIgnore @RequestParam AlarmEntity alarm, Query query) { + public R> alarms(AlarmEntity alarm, Query query) { return R.data(alarmService.alarms(alarm,Condition.getPage(query))); }