简体   繁体   中英

RabbitMQ Exchange not getting created using Spring-Cloud-Stream

I am new to Java Spring Cloud. I am trying to publish a message to an exchange using RabbitMQ. But once i run my java application, i do not see any Exchange being created. I am not getting any error too. What am i missing ?

I tried setting disk free limit to 200MB which was initially set to 50MB but still noticed no change.

The below is my code snippet for the controller class ::

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

     }

}

The below is my code snippet for the Message Sender class ::

@EnableBinding(Source.class)
public class AppointmentSender {

@Autowired
private Source source;

public boolean send(AppointmentEvent appointmentEvent) {
      return this.source.output().
      send(MessageBuilder.withPayload(appointmentEvent).build());
}

}

The below is the application.properties file

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

The below is 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>

An exchange with the name "appointments-exchange" is not getting created.

I just copied your properties into a new Boot project and it worked fine.

在此处输入图片说明

Does your guest user have admin permissions?

Try enabling DEBUG logging to see if there are any clues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM