feat(): 获取http连接的参数

dev.redis
ywt 2024-10-06 15:52:32 +08:00
parent 30560b90cf
commit 849d5328ac
8 changed files with 240 additions and 2 deletions

View File

@ -3,7 +3,10 @@ package com.muyu.cloud.vehicle.gateway.aliyun.controller;
import com.alibaba.nacos.api.model.v2.Result;
import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq;
import com.muyu.cloud.vehicle.gateway.aliyun.service.VehicleConnectionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -15,9 +18,13 @@ import org.springframework.web.bind.annotation.RestController;
*/
@Log4j2
@RestController
@RequestMapping
@RequestMapping("/vehicleGateway")
@Tag(name = "连接车辆控制层")
public class VehicleConnectionController {
@Autowired
private VehicleConnectionService vehicleConnectionService;
/**
* http
@ -27,7 +34,7 @@ public class VehicleConnectionController {
@PostMapping("/receiveMsg/connect")
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
log.info("=======>"+vehicleConnectionReq);
vehicleConnectionService.getConnect(vehicleConnectionReq);
return Result.success();
}
}

View File

@ -0,0 +1,9 @@
package com.muyu.cloud.vehicle.gateway.aliyun.mapper;
import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface VehicleConnectionMapper {
void addConnect(VehicleConnectionReq vehicleConnectionReq);
}

View File

@ -0,0 +1,12 @@
package com.muyu.cloud.vehicle.gateway.aliyun.service;
import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq;
public interface VehicleConnectionService {
/**
*
* @param vehicleConnectionReq
*/
void getConnect(VehicleConnectionReq vehicleConnectionReq);
}

View File

@ -0,0 +1,21 @@
package com.muyu.cloud.vehicle.gateway.aliyun.service.impl;
import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq;
import com.muyu.cloud.vehicle.gateway.aliyun.mapper.VehicleConnectionMapper;
import com.muyu.cloud.vehicle.gateway.aliyun.service.VehicleConnectionService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Log4j2
@Service
public class VehicleConnectionServiceImpl implements VehicleConnectionService {
@Autowired
private VehicleConnectionMapper vehicleConnectionMapper;
@Override
public void getConnect(VehicleConnectionReq vehicleConnectionReq) {
log.info("车辆连接请求:{}",vehicleConnectionReq.toString());
vehicleConnectionMapper.addConnect(vehicleConnectionReq);
}
}

View File

@ -0,0 +1,104 @@
package com.muyu.cloud.vehicle.gateway.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.Exchanger;
/**
* rabbitmq
*/
@Configuration
public class RabbitmqConfig {
/**
*
*/
private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class);
/**
*
*/
private static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
/**
*
*/
private static final String QUEUE_INFORM_SMS = "queue_inform_sms";
/**
*
*/
private static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
/**
* key
*/
private static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
/**
* key
*/
private static final String ROUTINGKEY_SMS = "inform.#.sms.#";
/**
*
*/
@Bean(EXCHANGE_TOPICS_INFORM)
public Exchange exchangeTopicsInform() {
try{
Exchange exchange = ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
logger.info("创建的交换机为:{}",EXCHANGE_TOPICS_INFORM);
return exchange;
} catch (Exception e) {
logger.error("创建该:{} 交换机失败",EXCHANGE_TOPICS_INFORM,e);
throw e;
}
}
/**
* QUEUE_INFORM_EMAIL
*/
@Bean(QUEUE_INFORM_EMAIL)
public Queue queueInformEmail() {
try{
Queue queue = new Queue(QUEUE_INFORM_EMAIL);
logger.info("创建的队列为:{}",QUEUE_INFORM_EMAIL);
return queue;
} catch (Exception e) {
logger.error("创建该:{} 队列失败",QUEUE_INFORM_EMAIL,e);
throw e;
}
}
/**
* QUEUE_INFORM_SMS
*/
@Bean(QUEUE_INFORM_SMS)
public Queue queueInformSms() {
try{
Queue queue = new Queue(QUEUE_INFORM_SMS);
logger.info("创建的队列为:{}",QUEUE_INFORM_SMS);
return queue;
} catch (Exception e) {
logger.error("创建该:{} 队列失败",QUEUE_INFORM_SMS,e);
throw e;
}
}
/**
* ROUTINGKEY_EMAILroutingKey
*/
@Bean
public Binding bindingExchangeInformEmail(@Qualifier(QUEUE_INFORM_EMAIL)Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM)Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
}
/**
* ROUTINGKEY_SMSroutingKey
*/
@Bean
public Binding bindingExchangeInformSms(@Qualifier(QUEUE_INFORM_SMS)Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM)Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
}
}

View File

@ -0,0 +1,28 @@
package com.muyu.cloud.vehicle.gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String,String> redisTemplate(RedisConnectionFactory redisConnectionFactory){
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
return redisTemplate;
}
}

View File

@ -0,0 +1,43 @@
package com.muyu.cloud.vehicle.gateway.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* rest
*/
@Log4j2
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
return new RestTemplate(factory);
}
/**
* HTTP
* 155
*
*
* @return
*/
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
try{
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
//设置读取超时时间为5秒
factory.setReadTimeout(5000);
//设置连接超时时间为15秒
factory.setConnectTimeout(15000);
return factory;
} catch (Exception e) {
//处理创建工厂或设置超时时间可能出现的异常
log.info("创建工厂失败:" + e.getMessage());
throw new RuntimeException("初始化HTTP请求失败",e);
}
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.cloud.vehicle.gateway.aliyun.mapper.VehicleConnectionMapper">
<insert id="addConnect">
insert into car_one_click_operation
(vehicle_vin,user_name,nonce,timestamp)
values
(#{vehicleVin},#{userName},#{nonce},#{timestamp})
</insert>
</mapper>