重构车辆上线消息消费逻辑并优化网关路由配置

- 重构了CarOnlineConsumer类,实现了车辆上线消息的监听和处理
- 新增了车辆网关交换机、队列和绑定的配置- 引入了cloud-modules-enterprise-cache依赖
- 添加了VehicleGatewayConstants类,用于定义车辆网关相关的常量
dev.carData
张腾 2024-10-10 17:23:41 +08:00
parent e986ab4a17
commit 628b8d1fab
3 changed files with 60 additions and 15 deletions

View File

@ -100,5 +100,11 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,16 +1,16 @@
package com.muyu.carData.consumer;
import com.muyu.carData.util.CacheUtil;
import com.muyu.domain.FaultCodeCache;
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationAddService;
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationFenceRespService;
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
/**线
@ -33,14 +33,31 @@ public class CarOnlineConsumer {
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "CAR_ONLINE",durable = "true"),
exchange = @Exchange(value = "ONLINE_EXCHANGE",type = "fanout")
))
public void online(String vin){
log.info("车辆vin:{},已上线,开始消费",vin);
FaultCodeCache faultCodeCache = vehicleCacheCarInformationAddService
.get(vehicleCacheCarInformationAddService.keyPre()+vin);
cacheUtil.put(vin,faultCodeCache);
/**
*
* @return
*/
@Bean
public DirectExchange initVehicleGatewayExchange(){
return new DirectExchange(VehicleGatewayConstants.VEHICLE_GETAWAY_EXCHANGE);
}
@Bean
@Primary
public Queue initQueue(){
return new Queue("test", true);
}
@Bean
public Binding binding1a(DirectExchange initVehicleGatewayExchange,
Queue initQueue) {
return BindingBuilder.bind(initQueue)
.to(initVehicleGatewayExchange)
.with(VehicleGatewayConstants.VEHICLE_GETAWAY_ROUTING_KEY);
}
@RabbitListener(queues = "test")
public void msg(String msg){
log.info(msg);
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.carData.consumer;
/**
* @Author
* @Packagecom.muyu.common.rabbit.contants
* @Projectcloud-server-8
* @nameVehicleGatewayContantsA
* @Date2024/10/10 9:02
*/
public class VehicleGatewayConstants {
/**
*
*/
public final static String VEHICLE_GETAWAY_EXCHANGE = "vehicle.getaway";
/**
* 线A
*/
public final static String VEHICLE_GETAWAY_ROUTING_KEY = "vehicle.getaway.online";
}