我想让Spring在heroku平台上使用CloudAMQP。 这是我的背景:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main-details">
<div class="ClassA" style="display:none;">
<div class="Inner-Details">
ClassA
</div>
<div class="Inner-Details">
</div>
</div>
<div class="ClassB" style="display:none;">
<div class="Inner-Details">
ClassB
</div>
<div class="Inner-Details">
</div>
</div>
<div class="ClassC" style="display:none;">
<div class="Inner-Details">
ClassC
</div>
<div class="Inner-Details">
</div>
</div>
</div>
但是我遇到了一些奇怪的事情:在本地它完全正常,传递CLOUDAMQP_URL = localhost,但在heroku上我得到以下异常:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<rabbit:connection-factory id="connectionFactory" host="#{systemEnvironment['CLOUDAMQP_URL']}"/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
exchange="myExchange" routing-key="foo.bar"/>
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="myQueue" />
<rabbit:topic-exchange name="myExchange">
<rabbit:bindings>
<rabbit:binding queue="myQueue" pattern="foo.*" />
</rabbit:bindings>
</rabbit:topic-exchange>
<rabbit:listener-container connection-factory="connectionFactory"
error-handler="exHandler">
<rabbit:listener ref="foo" method="listen" queue-names="myQueue" />
</rabbit:listener-container>
<bean id="foo" class="Foo" />
<bean id="exHandler" class="BackgroundRejectingErrorHandler" />
</beans>
我将$ {HEROKU_CLOUDAMQP_URL}替换为以下形式的实际连接字符串:
2017-05-24T13:56:00.062653+00:00 app[worker.1]: org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: ${HEROKU_CLOUDAMQP_URL}: invalid IPv6 address
2017-05-24T13:56:00.062655+00:00 app[worker.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:71)
2017-05-24T13:56:00.062655+00:00 app[worker.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:367)
2017-05-24T13:56:00.062656+00:00 app[worker.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565)
2017-05-24T13:56:00.062659+00:00 app[worker.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430)
2017-05-24T13:56:00.062660+00:00 app[worker.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411)
2017-05-24T13:56:00.062661+00:00 app[worker.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387)
2017-05-24T13:56:00.062661+00:00 app[worker.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336)
2017-05-24T13:56:00.062662+00:00 app[worker.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1136)
2017-05-24T13:56:00.062663+00:00 app[worker.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1387)
2017-05-24T13:56:00.062664+00:00 app[worker.1]: at java.lang.Thread.run(Thread.java:745)
完整堆栈跟踪:
amqp://$user:$password@HOST.cloudamqp.com/VHOST
我做错了吗?
提前致谢。
答案 0 :(得分:1)
修正了它。
显然兔子:连接工厂 - &gt; HOST&lt; - 无法处理完整的uri。 因此,必须拆分所有参数并一个接一个地传递它们。