java - 未使用 Spring-Cloud-Stream 创建 RabbitMQ Exchange
问题描述
我是 Java Spring Cloud 的新手。我正在尝试使用 RabbitMQ 将消息发布到交换。但是一旦我运行我的 java 应用程序,我就看不到任何正在创建的 Exchange。我也没有收到任何错误。我错过了什么?
我尝试将磁盘空闲限制设置为 200MB,最初设置为 50MB,但仍然没有发现任何变化。
下面是我的控制器类代码片段::
public class AppointmentController {
private static final Logger
logger=LoggerFactory.getLogger(AppointmentController.class);
@Autowired
AppointmentSender sender;
@PostMapping("/appointment-management-service/appointments")
public void bookAppointment(@RequestBody AppointmentEvent
appointmentEvent)
{
logger.info("Appointment request received {}",appointmentEvent);
appointmentEvent.setStatus(AppointmentStatus.INITIATED);
boolean isSent = sender.send(appointmentEvent);
logger.info("Appointment booking initiated {}",isSent);
}
}
下面是我的 Message Sender 类的代码片段::
@EnableBinding(Source.class)
public class AppointmentSender {
@Autowired
private Source source;
public boolean send(AppointmentEvent appointmentEvent) {
return this.source.output().
send(MessageBuilder.withPayload(appointmentEvent).build());
}
}
下面是 application.properties 文件
spring.application.name=appointment-management-service
server.port=8000
spring.jpa.show-sql=true
spring.h2.console.enabled=true
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.broker-url=tcp://127.0.0.1:5672
spring.rabbitmq.virtual-host= /
spring.cloud.stream.bindings.output.destination=appointments-exchange
下面是 pom.xml::
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.microservices</groupId>
<artifactId>appointmentmanagementsystem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>appointmentmanagementsystem</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
未创建名为“appointments-exchange”的交换。
解决方案
推荐阅读
- ansible - 我只是试图在每个剧本中写一个相同的错误
- awk - Print unique specific text form a line if it meet the search criteria
- php - 如何从 Google Sheets API 获取文本颜色格式?
- react-native - 删除查询使用 expo-sqlite 从两个表中删除条目
- python - 如何使用 lmxl 或 pykml 从 GE kml 中提取 LineString 元素颜色?
- javascript - 在多个视图中通过 Apps 脚本在表格中追加行
- python - 如何从 Python 读取返回的 Rust dll 指针
- swiftui - 如何使 SceneView 的背景透明?
- typescript - TypeScript:基于泛型构造类型化接口
- visual-studio - 如何在没有 Visual Studio 2019 将其扩展为 <:Phrase> 的情况下添加文本 :Phrase+TAB-Key