|
@@ -11,8 +11,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
|
|
|
* @author: yaoll
|
|
|
* @date: 2020-10-22
|
|
@@ -21,84 +19,98 @@ import java.io.IOException;
|
|
|
@Slf4j
|
|
|
@Configuration
|
|
|
public class JmsConfig {
|
|
|
-
|
|
|
-
|
|
|
- @Value("${persagy.dmp.exchange}")
|
|
|
- private String exchange;
|
|
|
-
|
|
|
- @Value("${persagy.dmp.alarm.routingKey}")
|
|
|
- private String dmpAlarmRoutingKey;
|
|
|
-
|
|
|
- @Value("${alarm.obj.routingKey}")
|
|
|
- private String alarmObjRoutingKey;
|
|
|
-
|
|
|
- @Value("${persagy.dmp.rwd.routingKey}")
|
|
|
- private String rwdRoutingKey;
|
|
|
-
|
|
|
- @Value("${persagy.dmp.alarm.queue}")
|
|
|
- private String alarmQueue;
|
|
|
-
|
|
|
-
|
|
|
- * 报警对象队列
|
|
|
- */
|
|
|
- private final String alarmObjQueue = "alarm-obj-queue";
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MessageProcesser messageProcesser;
|
|
|
-
|
|
|
- @Bean
|
|
|
- public TopicExchange exchange() {
|
|
|
- return new TopicExchange(exchange);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Queue alarmQueue() {
|
|
|
- return new Queue(alarmQueue, true);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Binding alarmBinding() {
|
|
|
- return BindingBuilder.bind(alarmQueue()).to(exchange()).with(dmpAlarmRoutingKey);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Binding rwdBinding() {
|
|
|
- return BindingBuilder.bind(alarmQueue()).to(exchange()).with(rwdRoutingKey);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Queue alarmObjQueue() {
|
|
|
- return new Queue(alarmObjQueue, true);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Binding alarmObjBinding() {
|
|
|
- return BindingBuilder.bind(alarmObjQueue()).to(exchange()).with(alarmObjRoutingKey);
|
|
|
- }
|
|
|
-
|
|
|
- @RabbitListener(queues = {alarmObjQueue})
|
|
|
- public void process(String message, Channel channel, Message msg) {
|
|
|
- log.info("============================== Receive:" + message);
|
|
|
- DmpMessage dmpMessage = JacksonMapper.toObject(message, DmpMessage.class);
|
|
|
- messageProcesser.listen(dmpMessage);
|
|
|
-
|
|
|
- try {
|
|
|
- channel.basicAck(msg.getMessageProperties().getDeliveryTag(),false);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("消息消费反馈失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RabbitListener(queues = "${persagy.dmp.alarm.queue}")
|
|
|
- public void process(DmpMessage message, Channel channel, Message msg) {
|
|
|
- log.info("============================== Receive:" + JacksonMapper.toSimpleJson(message));
|
|
|
- messageProcesser.listen(message);
|
|
|
-
|
|
|
- try {
|
|
|
- channel.basicAck(msg.getMessageProperties().getDeliveryTag(),false);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("消息消费反馈失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ ConsumeMessageThreadPool consumeMessageThreadPool;
|
|
|
+
|
|
|
+ @Value("${persagy.dmp.exchange}")
|
|
|
+ private String exchange;
|
|
|
+
|
|
|
+ @Value("${persagy.dmp.alarm.routingKey}")
|
|
|
+ private String dmpAlarmRoutingKey;
|
|
|
+
|
|
|
+ @Value("${alarm.obj.routingKey}")
|
|
|
+ private String alarmObjRoutingKey;
|
|
|
+
|
|
|
+ @Value("${persagy.dmp.rwd.routingKey}")
|
|
|
+ private String rwdRoutingKey;
|
|
|
+
|
|
|
+ @Value("${persagy.dmp.alarm.queue}")
|
|
|
+ private String alarmQueue;
|
|
|
+
|
|
|
+ @Value("${persagy.dmp.alarm.rwd.queue}")
|
|
|
+ private String alarmRwdQueue;
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Queue alarmRwdQueue() {
|
|
|
+ return new Queue(alarmRwdQueue, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Binding alarmRwdBinding() {
|
|
|
+ return BindingBuilder.bind(alarmRwdQueue()).to(exchange()).with(rwdRoutingKey);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 报警对象队列
|
|
|
+ */
|
|
|
+ private final String alarmObjQueue = "alarm-obj-queue";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageProcesser messageProcesser;
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public TopicExchange exchange() {
|
|
|
+ return new TopicExchange(exchange);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Queue alarmQueue() {
|
|
|
+ return new Queue(alarmQueue, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Binding alarmBinding() {
|
|
|
+ return BindingBuilder.bind(alarmQueue()).to(exchange()).with(dmpAlarmRoutingKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Queue alarmObjQueue() {
|
|
|
+ return new Queue(alarmObjQueue, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Binding alarmObjBinding() {
|
|
|
+ return BindingBuilder.bind(alarmObjQueue()).to(exchange()).with(alarmObjRoutingKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RabbitListener(queues = {alarmObjQueue})
|
|
|
+ public void process(String message, Channel channel, Message msg) throws Exception{
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("============================== Receive:" + message);
|
|
|
+ DmpMessage dmpMessage = JacksonMapper.toObject(message, DmpMessage.class);
|
|
|
+ if (dmpMessage != null) {
|
|
|
+ messageProcesser.listen(dmpMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ Boolean isRedeliveredFail = msg.getMessageProperties().getRedelivered();
|
|
|
+
|
|
|
+ if (isRedeliveredFail) {
|
|
|
+
|
|
|
+ log.error("重复消费消息失败,message: {}", message);
|
|
|
+ channel.basicReject(msg.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ channel.basicNack(msg.getMessageProperties().getDeliveryTag(), false, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RabbitListener(queues = {"${persagy.dmp.alarm.queue}", "${persagy.dmp.alarm.rwd.queue}"})
|
|
|
+ public void process(DmpMessage message, Channel channel, Message msg) {
|
|
|
+ consumeMessageThreadPool.consumeMessage(message, channel, msg);
|
|
|
+ }
|
|
|
}
|