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

Grails(spring-amqp) - connecting with RabbitMQ with SSL through XML configuration

我一直在尝试修改旧项目(基于 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 连接已建立。调试建议让我意识到我的错误。非常感谢。