我无法使用Spring Boot
向RabbitMQ
服务器发送消息。我没有看到任何异常。不知道发生了什么事。无法使用Spring Boot向RabbitMQ队列发送简单的“Hello World”消息
我对管理控制台RabbitMQ
拥有管理员级访问权限,并可以查看队列是否已创建。但是我没有看到任何队列被创建。而且在控制台日志中我看到的就是这个。
控制台日志:
2017-08-15 11:32:17.015 INFO 8256 --- [ main] com.study.jms.BasicApplication : Starting BasicApplication on KOP-DBT0J12 with PID 8256 (C:\NITAL\MY-DATA\CODE-SAMPLES\SPRINGBOOT-MESSAGING-SAMPLES\rabbitmq\rabbitmq-helloworld-producer-demo\target\classes started by chandeln in C:\NITAL\MY-DATA\CODE-SAMPLES\SPRINGBOOT-MESSAGING-SAMPLES\rabbitmq\rabbitmq-helloworld-producer-demo)
2017-08-15 11:32:17.020 INFO 8256 --- [ main] com.study.jms.BasicApplication : No active profile set, falling back to default profiles: default
2017-08-15 11:32:17.112 INFO 8256 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]73d4cc9e: startup date [Tue Aug 15 11:32:17 EDT 2017]; root of context hierarchy
2017-08-15 11:32:17.915 INFO 8256 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration' of type [org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration$$EnhancerBySpringCGLIB$$1c012f1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-08-15 11:32:18.739 INFO 8256 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-08-15 11:32:18.749 INFO 8256 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
2017-08-15 11:32:18.749 INFO 8256 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
2017-08-15 11:32:18.769 INFO 8256 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648
2017-08-15 11:32:18.779 INFO 8256 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2017-08-15 11:32:18.839 INFO 8256 --- [ main] com.study.jms.BasicApplication : Started BasicApplication in 2.208 seconds (JVM running for 2.668)
2017-08-15 11:32:18.883 INFO 8256 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#2cc44ad:0/[email protected] [delegate=amqp://[email protected]:5672/, localPort= 65025]
BasicApplication.java
@SpringBootApplication
public class BasicApplication {
private static RabbitTemplate rabbitTemplate;
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(BasicApplication.class, args);
rabbitTemplate = ctx.getBean(RabbitTemplate.class);
rabbitTemplate.convertAndSend("helloworld.q", "Hello World !");
}
}
application.properties
spring.rabbitmq.host=gsi-547576
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin
的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
您可以尝试[this](http://docs.spring.io/spring-amqp/reference/htmlsingle/#management-template),看看您是否能够获得所有已声明的队列? –
你跟着这个https://spring.io/guides/gs/messaging-rabbitmq/? – Barath
@Darshan - 是的,我确实收到200个OK队列名称的响应 – user2325154