gpt4 book ai didi

xml - Grails(spring-amqp) - 通过 XML 配置使用 SSL 连接 RabbitMQ

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:33 25 4
gpt4 key购买 nike

我一直在尝试修改旧项目(基于 grails 2.5.6)的配置,以便在与 RabbitMQ 实例集成时使用 ssl 连接。我有 1.4.6 版的 spring-amqp。我的旧版本配置是用这样的 xml 文件编写的:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<rabbit:connection-factory
id="connectionFactory"
username="guest2"
password="guest"
virtual-host="dev"
host="localhost"
port="5672"
/>

我也有这样配置的监听器:

<bean id="rabbitListener" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="queues" ref="rabbitQueue" />
<property name="defaultRequeueRejected" value="false"/>
<property name="messageListener" ref="listenerService" />
<property name="errorHandler" ref="errorHandlerService" />
<property name="autoStartup" value="false" />
<property name="concurrentConsumers" value="1" />
</bean>

我已经设置了 rabbitmq 服务器,所以它在端口 5671 上有可用的 ssl 连接。然后根据我在这里找到的文档:spring-documentation ,我已经修改了 xml 配置,如下所示:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<rabbit:connection-factory
id="connectionFactory"
connection-factory="clientConnectionFactory"
username="guest2"
password="guest"
virtual-host="dev"
host="localhost"
port="5671"
/>

<bean id="clientConnectionFactory"
class="org.springframework.xd.dirt.integration.rabbit.RabbitConnectionFactoryBean">
<property name="useSSL" value="true" />
<property name="sslPropertiesLocation" value="file://./rabbitSSL.properties"/>
</bean>

在运行应用程序时使用该配置我得到如下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitListener' defined in URL [file:/target/classes/rabbitmq/resources-listeners.xml]: Cannot resolve reference to bean 'connectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory': Cannot create inner bean '(inner bean)#50b63731' of type [org.springframework.xd.dirt.integration.rabbit.RabbitConnectionFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#50b63731': Invocation of init method failed; nested exception is java.net.UnknownHostException: .

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#50b63731': Invocation of init method failed; nested exception is java.net.UnknownHostException: .

我一直在努力解决这个问题。我不确定如何解释此错误以及如何解决它。有没有人遇到过类似的问题或者可能知道此配置可能有什么问题?

最佳答案

这是一个迟到的回复,但我已经找到了问题所在。一直都是我的错。调试后我发现 sslPropertiesLocation 设置不正确。 file://./rabbit.. 中的双 / 使其转到不正确的 ftp 位置。设置正确的文件位置后,如:file:grails-app/conf/rabbit/file 连接已设置。调试建议让我意识到我的错误。非常感谢。

关于xml - Grails(spring-amqp) - 通过 XML 配置使用 SSL 连接 RabbitMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48641331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com