MQ整合
This commit is contained in:
parent
979f85f055
commit
1c7c41ccdf
@ -24,7 +24,7 @@ public class MqController {
|
||||
private MqService mqService;
|
||||
|
||||
@GetMapping("/sendMsg")
|
||||
public Mono sendMsg() {
|
||||
public Mono<Boolean> sendMsg() {
|
||||
UserHomeEntity userHomeEntity = new UserHomeEntity();
|
||||
userHomeEntity.setUserId(1L);
|
||||
userHomeEntity.setHomeName("小米的家");
|
||||
@ -32,10 +32,10 @@ public class MqController {
|
||||
|
||||
Mono<Boolean> booleanMono = mqService.sendMessageWithConfirmation(YunxiRabbitConst.EXCHANGE_YUNXI_EVENT, YunxiRabbitConst.ROUTE_KEY_YUNXI, userHomeEntity);
|
||||
return booleanMono.flatMap(res -> {
|
||||
if (!res) {
|
||||
if (res.equals(Boolean.FALSE)) {
|
||||
return Mono.error(new RuntimeException("消息发送失败"));
|
||||
} else {
|
||||
return Mono.just(true);
|
||||
return Mono.just(Boolean.TRUE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
package com.qiuguo.iot.user.api.rabbit;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyConsumer {
|
||||
|
||||
@RabbitListener(queues = "my-queue")
|
||||
public void receiveMessage(String message) {
|
||||
// 处理接收到的消息
|
||||
System.out.println("Received message: " + message);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.qiuguo.iot.user.api.rabbit;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyProducer {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
public void sendMessage(String message) {
|
||||
//发送消息
|
||||
rabbitTemplate.convertAndSend("my-queue", message);
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package com.qiuguo.iot.user.api.rabbit;
|
||||
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
@Bean
|
||||
public Queue myQueue() {
|
||||
return new Queue("my-queue");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user