瀏覽代碼

增加消息队列回调

lixing 3 年之前
父節點
當前提交
aae83502df

+ 15 - 6
dmp-alarm/src/main/java/com/persagy/dmp/alarm/jms/JmsConfig.java

@@ -11,6 +11,8 @@ 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
@@ -74,16 +76,23 @@ public class JmsConfig {
 		return BindingBuilder.bind(alarmObjQueue()).to(exchange()).with(alarmObjRoutingKey);
 	}
 
-	@RabbitListener(queues = alarmObjQueue)    //监听器监听指定的Queue
+	@RabbitListener(queues = {alarmObjQueue, "${persagy.dmp.alarm.queue}"})    //监听器监听指定的Queue
 	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}")    //监听器监听指定的Queue
-	public void process(DmpMessage message) {
-		log.info("============================== Receive:" + JacksonMapper.toSimpleJson(message));
-		messageProcesser.listen(message);
-	}
+//	@RabbitListener(queues = "${persagy.dmp.alarm.queue}")    //监听器监听指定的Queue
+//	public void process(DmpMessage message) {
+//		log.info("============================== Receive:" + JacksonMapper.toSimpleJson(message));
+//		messageProcesser.listen(message);
+//	}
+
 }

+ 1 - 0
dmp-alarm/src/main/java/com/persagy/dmp/alarm/jms/MessageProcesser.java

@@ -78,6 +78,7 @@ public class MessageProcesser {
 			DmpParameterStorage.set(data);
 
 			executor.execute(message);
+
 		} catch (Exception e) {
 			e.printStackTrace();
 		} finally {

+ 6 - 1
dmp-org/src/main/resources/bootstrap.yml

@@ -1,7 +1,12 @@
 spring:
   application:
     name: dmp-org
+  profiles:
+    active: log-test
   cloud:
     config:
       profile: dev
-      uri: http://localhost:9932
+      uri: http://192.168.64.18:9932
+persagy:
+  log:
+    path: ../logs/dmp-org/