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