upd
parent
94c473ecab
commit
f251581efb
26
pom.xml
26
pom.xml
|
@ -53,6 +53,32 @@
|
|||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<!-- rabbitMQ -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
<version>2.7.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dragon</groupId>
|
||||
<artifactId>dragon-common-core</artifactId>
|
||||
<version>3.6.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dragon</groupId>
|
||||
<artifactId>dragon-common-redis</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.32</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.vehicle.controller;
|
|||
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
import com.vehicle.service.VehicleService;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -23,6 +24,7 @@ public class VehicleOnlineController {
|
|||
@Autowired
|
||||
private VehicleService vehicleService;
|
||||
|
||||
|
||||
/**
|
||||
* 将车辆在线请求转换为车辆在线对象
|
||||
*
|
||||
|
@ -30,9 +32,9 @@ public class VehicleOnlineController {
|
|||
*/
|
||||
@PostMapping("/online")
|
||||
public String vehicleOnline(@RequestBody @Validated VehicleOnlineReq vehicleOnlineReq) {
|
||||
vehicleService.vehicleOnline(vehicleOnlineReq);
|
||||
String topic = vehicleService.vehicleOnline(vehicleOnlineReq);
|
||||
//返回该车辆的主题
|
||||
return "topic_"+vehicleOnlineReq.getVin();
|
||||
return topic;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,5 @@ public class VehicleOnlineReq {
|
|||
/**
|
||||
* 车辆登陆密码
|
||||
*/
|
||||
@NotNull(message = "密码不能为空")
|
||||
private String password;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import com.vehicle.domain.common.req.VehicleOnlineReq;
|
|||
* @date 2023/11/27 14:26
|
||||
*/
|
||||
public interface VehicleService extends IService<VehicleOnlineReq> {
|
||||
void vehicleOnline(VehicleOnlineReq vehicleOnlineReq);
|
||||
String vehicleOnline(VehicleOnlineReq vehicleOnlineReq);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.vehicle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.dragon.common.redis.service.RedisService;
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
import com.vehicle.mapper.VehicleOnlineMapper;
|
||||
import com.vehicle.service.VehicleService;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.vehicle.utils.Md5Util.md5Encrypt;
|
||||
|
||||
|
||||
|
@ -18,23 +22,33 @@ import static com.vehicle.utils.Md5Util.md5Encrypt;
|
|||
*/
|
||||
@Service
|
||||
public class VehicleServiceImpl extends ServiceImpl<VehicleOnlineMapper, VehicleOnlineReq> implements VehicleService {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 车辆上线请求的回调函数
|
||||
*
|
||||
* @param vehicleOnlineReq 车辆上线请求参数
|
||||
*/
|
||||
@Override
|
||||
public void vehicleOnline(VehicleOnlineReq vehicleOnlineReq) {
|
||||
public String vehicleOnline(VehicleOnlineReq vehicleOnlineReq) {
|
||||
|
||||
String vin = vehicleOnlineReq.getVin();
|
||||
String username = vehicleOnlineReq.getUsername();
|
||||
String time = System.currentTimeMillis() + "";
|
||||
// String time = vehicleOnlineReq.getOnlineTime().getTime() + "";
|
||||
String message=vin+time+username; // 拼接所要加密消息
|
||||
String message = vin + time + username; // 拼接所要加密消息
|
||||
String password = md5Encrypt(message); // 加密
|
||||
vehicleOnlineReq.setPassword(password);
|
||||
this.save(vehicleOnlineReq);
|
||||
rabbitTemplate.convertAndSend("sub_top", "topic_" + vehicleOnlineReq.getVin(), msg -> {
|
||||
msg.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
return msg;
|
||||
});
|
||||
return "topic_" + vehicleOnlineReq.getVin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
spring:
|
||||
redis:
|
||||
host: 10.100.1.2
|
||||
port: 6379
|
||||
password:
|
||||
application:
|
||||
name: mqttDemo
|
||||
datasource:
|
||||
|
@ -6,5 +10,18 @@ spring:
|
|||
url: jdbc:mysql://124.221.216.186:3306/mqtt?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 27a9601cb3545824
|
||||
rabbitmq:
|
||||
host: 182.254.222.21
|
||||
port: 5672
|
||||
template:
|
||||
mandatory: true
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次取一条消息消费 消费完成取下一条
|
||||
acknowledge-mode: manual # 设置消费端手动ack确认
|
||||
retry:
|
||||
enabled: true # 支持重试
|
||||
publisher-confirms: true #确认消息已发送到交换机(Exchange)
|
||||
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||
server:
|
||||
port: 8066
|
||||
port: 8067
|
||||
|
|
Loading…
Reference in New Issue