This commit is contained in:
simon 2023-09-26 13:50:46 +08:00
parent 979f85f055
commit 1c7c41ccdf
4 changed files with 3 additions and 48 deletions

View File

@ -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);
}
});
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}