master
冯凯 2023-12-13 09:19:31 +08:00
parent b0305ca9ee
commit 205418d9f4
6 changed files with 68 additions and 23 deletions

View File

@ -6,13 +6,14 @@ EXPOSE 8067
VOLUME /home/logs/vehicleTest VOLUME /home/logs/vehicleTest
#构建复制外部文件到docker #构建复制外部文件到docker
COPY /target/vehicletest.jar /home/app.jar COPY /target/vehicletest.jar /home/app.jar
COPY /skywalking-agent.jar /home/skywalking-agent.jar
#工作目录 exec -it 进入容器内部后的默认的起始目录 #工作目录 exec -it 进入容器内部后的默认的起始目录
WORKDIR /home WORKDIR /home
ENV TIME_ZONE Asia/Shanghai ENV TIME_ZONE Asia/Shanghai
#指定东八区 #指定东八区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-javaagent:/home/skywalking-agent.jar","-Dskywalking.agent.service_name=xxxtest","-Dskywalking.collector.backend_service=124.221.216.186:11800","-jar","/home/app.jar"]
#启动java 程序 ##启动java 程序
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"] #ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"]

View File

@ -59,11 +59,6 @@
<artifactId>spring-boot-starter-amqp</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
<version>2.6.2</version> <version>2.6.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.7.15</version>
</dependency>
<dependency> <dependency>
<groupId>com.dragon</groupId> <groupId>com.dragon</groupId>
<artifactId>dragon-common-core</artifactId> <artifactId>dragon-common-core</artifactId>

Binary file not shown.

View File

@ -2,6 +2,9 @@ package com.vehicle;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
/** /**
* @author * @author
@ -15,4 +18,11 @@ public class VehicleTestApp {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(VehicleTestApp.class,args); SpringApplication.run(VehicleTestApp.class,args);
} }
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
return container;
}
} }

View File

@ -4,19 +4,19 @@ package com.vehicle.controller;
import com.dragon.common.redis.service.RedisService; import com.dragon.common.redis.service.RedisService;
import com.vehicle.domain.common.req.VehicleOnlineReq; import com.vehicle.domain.common.req.VehicleOnlineReq;
import com.vehicle.service.VehicleService; import com.vehicle.service.VehicleService;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vehicle.utils.Conn;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.websocket.server.PathParam;
import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @author * @author
@ -35,6 +35,7 @@ public class VehicleOnlineController {
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
/** /**
* 线线 * 线线
* *
@ -42,7 +43,11 @@ public class VehicleOnlineController {
*/ */
@PostMapping("/online") @PostMapping("/online")
public String vehicleOnline(@RequestBody @Validated VehicleOnlineReq vehicleOnlineReq) { public String vehicleOnline(@RequestBody @Validated VehicleOnlineReq vehicleOnlineReq) {
String topic = vehicleService.vehicleOnline(vehicleOnlineReq); String topic = vehicleService.vehicleOnline(vehicleOnlineReq);
List<String> eventList = new ArrayList<>();
Collections.addAll(eventList, "historyTrackEvent", "faultEvent");
redisService.setCacheList("event_" + vehicleOnlineReq.getVin(), eventList);
//返回该车辆的主题 //返回该车辆的主题
log.info("topic:{}", topic); log.info("topic:{}", topic);
return topic; return topic;
@ -50,13 +55,25 @@ public class VehicleOnlineController {
} }
@PostMapping("/upd") @PostMapping("/upd")
public void updRedis(){ public void updRedis() {
List<String> strings = redisService.getCacheList("vin"); List<String> strings = redisService.getCacheList("vin");
redisService.deleteObject("vin"); redisService.deleteObject("vin");
Collections.addAll(strings,"123456","888888"); Collections.addAll(strings, "123456", "888888");
// System.out.println(cacheList); // System.out.println(cacheList);
redisService.setCacheList("vin",strings); redisService.setCacheList("vin", strings);
} }
@PostMapping("/fence/{vin}")
public void fence(@PathVariable String vin) {
// ArrayList<String> fenceList = new ArrayList<>();
// fenceList.add("fenceEvent");
redisService.setCacheObject(vin, "java", 10L, TimeUnit.SECONDS);
}
@GetMapping("/test")
public void dataTest(@RequestParam("databaseName") String databaseName, @RequestParam("tName")String tName){
Conn.select(databaseName,tName);
}
} }

View File

@ -0,0 +1,22 @@
package com.vehicle.utils;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
@Override
protected void doHandleMessage(Message message) {
String expiredKey = message.toString();
if (expiredKey.startsWith("fault"))
// 处理过期键的逻辑
System.out.println("Key expired: " + expiredKey);
}
}