|
@@ -2,9 +2,6 @@ package com.fjhx.service.amqp.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.utils.amqp.AmqpClient;
|
|
|
-import com.fjhx.utils.amqp.AmqpClientOptions;
|
|
|
-import com.fjhx.utils.amqp.AmqpConstants;
|
|
|
import com.fjhx.constants.IotProductionRedisPrefixConstant;
|
|
|
import com.fjhx.entity.amqp.AmqpData;
|
|
|
import com.fjhx.mapper.amqp.AmqpDataMapper;
|
|
@@ -13,11 +10,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.jms.JMSException;
|
|
|
import javax.jms.Message;
|
|
|
-import javax.jms.MessageConsumer;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -38,50 +33,6 @@ public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> i
|
|
|
@Resource
|
|
|
private BladeRedis redisCache;
|
|
|
|
|
|
- @PostConstruct
|
|
|
- public void listener() throws Exception {
|
|
|
- AmqpClientOptions options = AmqpClientOptions.builder()
|
|
|
- .host(AmqpConstants.HOST)
|
|
|
- .port(AmqpConstants.PORT)
|
|
|
- .accessKey(AmqpConstants.ACCESS_KEY)
|
|
|
- .accessCode(AmqpConstants.ACCESS_CODE)
|
|
|
- .queuePrefetch(1000) // sdk会在内存中分配该参数大小的队列,用来接收消息,客户端内存较小的情况可以调小该参数。
|
|
|
- .build();
|
|
|
- AmqpClient amqpClient = new AmqpClient(options);
|
|
|
- amqpClient.initialize();
|
|
|
- MessageConsumer consumer = amqpClient.newConsumer(AmqpConstants.DEFAULT_QUEUE);
|
|
|
- consumer.setMessageListener(message -> {
|
|
|
- try {
|
|
|
- // 此处进行消息处理。如果处理比较耗时,最好进行开启新的线程处理,否则可能造成心跳超时链接断开。
|
|
|
- saveData(message);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("message.getBody error,exception is ", e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-// @PostConstruct
|
|
|
-// public void listener2() throws Exception {
|
|
|
-// AmqpClientOptions options = AmqpClientOptions.builder()
|
|
|
-// .host(AmqpConstants.HOST)
|
|
|
-// .port(AmqpConstants.PORT)
|
|
|
-// .accessKey("oZvmUesgndzlw75ShbswJOe36algwcvaGBmOAsxc")
|
|
|
-// .accessCode("Y6JLYH6QV0LX5AJDXREM")
|
|
|
-// .queuePrefetch(1000) // sdk会在内存中分配该参数大小的队列,用来接收消息,客户端内存较小的情况可以调小该参数。
|
|
|
-// .build();
|
|
|
-// AmqpClient amqpClient = new AmqpClient(options);
|
|
|
-// amqpClient.initialize();
|
|
|
-// MessageConsumer consumer = amqpClient.newConsumer(AmqpConstants.DEFAULT_QUEUE);
|
|
|
-// consumer.setMessageListener(message -> {
|
|
|
-// try {
|
|
|
-// System.err.println(message);
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.warn("message.getBody error,exception is ", e);
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
private void saveData(Message message) {
|
|
|
try {
|
|
|
|
|
@@ -95,7 +46,6 @@ public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> i
|
|
|
String status = bodyObj.getString("status");
|
|
|
if (status != null) {
|
|
|
System.out.println(jsonObject);
|
|
|
-
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -114,7 +64,6 @@ public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> i
|
|
|
message.acknowledge();
|
|
|
|
|
|
} catch (JMSException e) {
|
|
|
- // TODO 消息保存失败处理
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|