重构车辆上线消息消费逻辑并优化网关路由配置
- 重构了CarOnlineConsumer类,实现了车辆上线消息的监听和处理 - 新增了车辆网关交换机、队列和绑定的配置- 引入了cloud-modules-enterprise-cache依赖 - 添加了VehicleGatewayConstants类,用于定义车辆网关相关的常量dev.carData
parent
e986ab4a17
commit
628b8d1fab
|
@ -100,5 +100,11 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
<artifactId>cloud-common-rabbit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package com.muyu.carData.consumer;
|
package com.muyu.carData.consumer;
|
||||||
|
|
||||||
import com.muyu.carData.util.CacheUtil;
|
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 com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
import org.springframework.amqp.core.Binding;
|
||||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
import org.springframework.amqp.core.DirectExchange;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
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")
|
* @return
|
||||||
))
|
*/
|
||||||
public void online(String vin){
|
@Bean
|
||||||
log.info("车辆vin:{},已上线,开始消费",vin);
|
public DirectExchange initVehicleGatewayExchange(){
|
||||||
FaultCodeCache faultCodeCache = vehicleCacheCarInformationAddService
|
return new DirectExchange(VehicleGatewayConstants.VEHICLE_GETAWAY_EXCHANGE);
|
||||||
.get(vehicleCacheCarInformationAddService.keyPre()+vin);
|
}
|
||||||
cacheUtil.put(vin,faultCodeCache);
|
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.carData.consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.common.rabbit.contants
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleGatewayContantsA
|
||||||
|
* @Date:2024/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";
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue