Browse Source

#告警修改

zhongwei
yang_shj 1 year ago
parent
commit
cb8997c820
  1. 27
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  2. 45
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java
  3. 8
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java
  4. 16
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  5. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java

27
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<Object, Object> redisTemplate;
@Override
public void onMessage(Message message, byte[] pattern) {
RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
String msg = serializer.deserialize(message.getBody());
System.out.println("接收到的消息是:" + msg);
}
}

45
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");
}
}

8
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 {
}

16
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 {
}

2
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") @PostMapping("/show")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "告警列表分页", notes = "传入: AlarmConfigEntity对象,分页参数") @ApiOperation(value = "告警列表分页", notes = "传入: AlarmConfigEntity对象,分页参数")
public R<IPage<AlarmEntity>> alarms(@ApiIgnore @RequestParam AlarmEntity alarm, Query query) { public R<IPage<AlarmEntity>> alarms(AlarmEntity alarm, Query query) {
return R.data(alarmService.alarms(alarm,Condition.getPage(query))); return R.data(alarmService.alarms(alarm,Condition.getPage(query)));
} }

Loading…
Cancel
Save