Spring 启动云 + RabbitMQ

Spring Boot Cloud + RabbitMQ

我是 Spring、Spring Boot 和 RabbitMQ 的新手。不过我还可以 programmer/problem 解算器。

最近我开始阅读这本书 Learning Spring Boot 2.0 - Second Edition,可以在此处找到相关代码 https://github.com/learning-spring-boot/learning-spring-boot-2nd-edition-code。 我认为事情对我来说进展顺利……到处都是小问题,但只要我能够进步和学习,我认为我做得很好。

我刚刚读完这本书的一半,然后作者开始谈论 Spring Cloud Streams 和 RabbitMQ。 我现在正在使用此处找到的代码 https://github.com/learning-spring-boot/learning-spring-boot-2nd-edition-code/tree/master/6/part3.

我的代码没有产生错误,但也没有产生预期的结果。当我 运行 应用程序时,图像评论似乎没有被保存或显示。我收到这样的日志消息

o.s.a.r.c.CachingConnectionFactory : Created new connection: SpringAMQP#2920fd66:0/SimpleConnection@59ae4da8 [delegate=amqp://guest@127.0.0.1:5672/, localPort= 57615]

当我提交数据时。

但是书上说我应该收到如下消息:

o.s.integration.channel.DirectChannel : preSent on channel input, message: GenericMessage [payload=Comment(id=null,imageId=book.jpg)]

看看我应该得到什么,我认为问题可能与渠道有关。也许不是频道的问题,也许是别的问题。

我应该如何找到问题的确切原因?

我不熟悉 Greg 的书,但我刚刚将该应用程序加载到 Eclipse 中,它似乎对我来说工作正常。上传图片后,它会显示在列表中。

然后我对图片发表评论,我看到...

2018-01-19 00:04:41.046 DEBUG 16612 --- [ctor-http-nio-3] o.s.integration.channel.DirectChannel : preSend on channel 'output', message: GenericMessage [payload=com.greglturnquist.learningspringboot.comments.Comment@4d4f990f, headers={id=0651f9b9-e38b-1557-67dd-bc19acae8af1, timestamp=1516338281044}]

...

2018-01-19 00:07:35.570 DEBUG 17539 --- [g-spring-boot-1] o.s.integration.channel.DirectChannel : preSend on channel 'input', message: GenericMessage [payload=byte[64], headers={amqp_receivedDeliveryMode=PERSISTENT, amqp_receivedRoutingKey=learning-spring-boot-comments, amqp_receivedExchange=learning-spring-boot-comments, amqp_deliveryTag=1, amqp_consumerQueue=learning-spring-boot-comments.learning-spring-boot, amqp_redelivered=false, id=43094b53-d9b5-115e-db44-dcef73a0a9c4, amqp_consumerTag=amq.ctag-MGTGY6EuPidJy3BH7_j2zw, contentType=application/json, timestamp=1516338455570}]

但我确实看到了

2018-01-19 00:07:54.291 ERROR 17539 --- [ctor-http-nio-3] o.s.w.s.h.ResponseStatusExceptionHandler : Response status 405 with reason "Request method 'GET' not supported"

我不确定您是否应该看到已发布的评论。

How should I go about finding the exact cause of this of the problem?

第一步是为根记录器(或所有 org.springframework)启用 DEBUG 日志记录。

您可能想要 reach out to Greg on his web site