|
@@ -2,18 +2,18 @@ package com.fjhx.service.amqp.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.config.amqp.AmqpClient;
|
|
|
-import com.fjhx.config.amqp.AmqpConstants;
|
|
|
+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;
|
|
|
import com.fjhx.service.amqp.AmqpDataService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.CommandLineRunner;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.jms.JMSException;
|
|
|
import javax.jms.Message;
|
|
@@ -33,16 +33,22 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> implements AmqpDataService, CommandLineRunner {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AmqpClient amqpClient;
|
|
|
+public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> implements AmqpDataService {
|
|
|
|
|
|
@Resource
|
|
|
private BladeRedis redisCache;
|
|
|
|
|
|
- @Override
|
|
|
- public void run(String... args) throws Exception {
|
|
|
+ @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)
|
|
|
+ .build();
|
|
|
+ AmqpClient amqpClient = new AmqpClient(options);
|
|
|
+ amqpClient.initialize();
|
|
|
MessageConsumer consumer = amqpClient.newConsumer(AmqpConstants.DEFAULT_QUEUE);
|
|
|
consumer.setMessageListener(message -> {
|
|
|
try {
|
|
@@ -54,6 +60,28 @@ public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> i
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void saveData(Message message) {
|
|
|
try {
|
|
|
|