feat(): 获取http连接的参数
parent
30560b90cf
commit
849d5328ac
|
@ -3,7 +3,10 @@ package com.muyu.cloud.vehicle.gateway.aliyun.controller;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.model.v2.Result;
|
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.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 lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -15,9 +18,13 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping
|
@RequestMapping("/vehicleGateway")
|
||||||
|
@Tag(name = "连接车辆控制层")
|
||||||
public class VehicleConnectionController {
|
public class VehicleConnectionController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleConnectionService vehicleConnectionService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取http连接的参数
|
* 获取http连接的参数
|
||||||
|
@ -27,7 +34,7 @@ public class VehicleConnectionController {
|
||||||
@PostMapping("/receiveMsg/connect")
|
@PostMapping("/receiveMsg/connect")
|
||||||
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||||
log.info("=======>"+vehicleConnectionReq);
|
log.info("=======>"+vehicleConnectionReq);
|
||||||
|
vehicleConnectionService.getConnect(vehicleConnectionReq);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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_EMAIL队列绑定交换机,指定routingKey
|
||||||
|
*/
|
||||||
|
@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_SMS队列绑定交换机,指定routingKey
|
||||||
|
*/
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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请求工厂实例。
|
||||||
|
* 注意:这里设置了连接和读取数据的超时时间,分别设为15秒和5秒。
|
||||||
|
* 这些值可以根据实际网络状况和应用需求进行调整。
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
Loading…
Reference in New Issue