ffffff
parent
94a0e48edc
commit
404f434d62
|
@ -23,11 +23,15 @@ import org.springframework.context.annotation.Primary;
|
|||
@Configuration
|
||||
@Slf4j
|
||||
public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
|
||||
// 通过注入的方式获取队列名、交换机名和路由键
|
||||
//队列名
|
||||
@Value("queueName")
|
||||
public String queueName;
|
||||
|
||||
//队列名
|
||||
public static final String finByVinQueueName="finByVinQueueName";
|
||||
//交换机
|
||||
public static final String VinExchangeName="vinExchangeName";
|
||||
//路由键
|
||||
public static final String VinRoutingKey="vinRoutingKey";
|
||||
//队列名
|
||||
public static final String FENCE_QUEUE ="fenceQueue";
|
||||
|
||||
|
@ -71,6 +75,10 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
|
|||
public Queue queue2() {
|
||||
return new Queue(FENCE_QUEUE, true);
|
||||
}
|
||||
@Bean("finByVinQueueName")
|
||||
public Queue finByVinQueueName() {
|
||||
return new Queue(finByVinQueueName, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
|
@ -89,6 +97,12 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
|
|||
return new DirectExchange(FENCE_EXCHANGE);
|
||||
}
|
||||
|
||||
@Bean("vinExchangeName")
|
||||
public DirectExchange vinExchangeName() {
|
||||
return new DirectExchange(VinExchangeName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:27
|
||||
|
@ -135,6 +149,10 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
|
|||
public Binding binding2() {
|
||||
return BindingBuilder.bind(queue2()).to(directExchange2()).with(FENCE_ROUTINGKEY);
|
||||
}
|
||||
@Bean("vinRoutingKey")
|
||||
public Binding binding3() {
|
||||
return BindingBuilder.bind(finByVinQueueName()).to(vinExchangeName()).with(VinRoutingKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
|
|
|
@ -11,10 +11,7 @@ import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
|
@ -27,14 +24,24 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@Slf4j
|
||||
public class MqController {
|
||||
// 通过注入的方式获取队列名、交换机名和路由键
|
||||
|
||||
//队列名
|
||||
// @Value("finByVinQueueName")
|
||||
// public static final String finByVinQueueName="finByVinQueueName";
|
||||
// //交换机
|
||||
// @Value("vinExchangeName")
|
||||
// public String VinExchangeName="vinExchangeName";
|
||||
// //路由键
|
||||
// @Value("vinRoutingKey")
|
||||
// public String VinRoutingKey="vinRoutingKey";
|
||||
|
||||
//队列名
|
||||
@Value("queueName")
|
||||
public String queueName;
|
||||
@Value("finByVinQueueName")
|
||||
public String finByVinQueueName;
|
||||
|
||||
//交换机
|
||||
@Value("exchangeName")
|
||||
public String exchangeName;
|
||||
public String exchangeName="exchangeName";
|
||||
|
||||
//路由键
|
||||
@Value("routingKey")
|
||||
|
@ -62,11 +69,13 @@ public class MqController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("findByVin")
|
||||
public void postFindByVin(@RequestBody RealTimeDataRequest request){
|
||||
@PostMapping("findByVin/{vin}")
|
||||
public void postFindByVin(@PathVariable String vin){
|
||||
RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest();
|
||||
realTimeDataRequest.setVin(vin);
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
request.setUserId(userId);
|
||||
rabbitTemplate.convertAndSend(exchangeName, routingKey, request, message -> {
|
||||
realTimeDataRequest.setUserId(userId);
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.VinExchangeName, RabbitMQConfig.VinRoutingKey, realTimeDataRequest, message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.randomUUID());
|
||||
return message;
|
||||
}, new CorrelationData(IdUtils.randomUUID())
|
||||
|
|
Loading…
Reference in New Issue