sky
parent
b0305ca9ee
commit
205418d9f4
|
@ -6,13 +6,14 @@ EXPOSE 8067
|
|||
VOLUME /home/logs/vehicleTest
|
||||
#构建复制外部文件到docker
|
||||
COPY /target/vehicletest.jar /home/app.jar
|
||||
COPY /skywalking-agent.jar /home/skywalking-agent.jar
|
||||
#工作目录 exec -it 进入容器内部后的默认的起始目录
|
||||
WORKDIR /home
|
||||
ENV TIME_ZONE Asia/Shanghai
|
||||
#指定东八区
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
#启动java 程序
|
||||
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"]
|
||||
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 程序
|
||||
#ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"]
|
||||
|
||||
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -59,11 +59,6 @@
|
|||
<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>
|
||||
|
|
Binary file not shown.
|
@ -2,6 +2,9 @@ package com.vehicle;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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 冯凯
|
||||
|
@ -15,4 +18,11 @@ public class VehicleTestApp {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleTestApp.class,args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,19 @@ package com.vehicle.controller;
|
|||
import com.dragon.common.redis.service.RedisService;
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
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.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
|
@ -35,6 +35,7 @@ public class VehicleOnlineController {
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
/**
|
||||
* 将车辆在线请求转换为车辆在线对象
|
||||
*
|
||||
|
@ -42,7 +43,11 @@ public class VehicleOnlineController {
|
|||
*/
|
||||
@PostMapping("/online")
|
||||
public String vehicleOnline(@RequestBody @Validated VehicleOnlineReq 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);
|
||||
return topic;
|
||||
|
@ -59,4 +64,16 @@ public class VehicleOnlineController {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue