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

标签 xml ssl grails config spring-amqp

我一直在尝试修改旧项目(基于 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/

相关文章:

php - 在 Apache 上强制使用 HTTPS 并产生奇怪的结果

php - 强制 Heroku PHP 应用程序对 www 和非 www 版本都使用 https

node.js - 主页未解析裸域 URL

hibernate - Grails 2.5至Grails 3.2 GORM 6

python - 如何使用 Python LXML Objectify 创建相同的 XML 元素 3 次

java - onClick 方法不存在

java - 无法解析 xml 条目

unit-testing - Grails:运行派生的test-app时出错:无此类属性:类:_Events的Ant

grails - Grails应用升级2.5-dataSource为null

xml - 如何使用 VBA 将数据从 XML 文件提取到 Excel 工作表