【问题标题】:Grails(spring-amqp) - connecting with RabbitMQ with SSL through XML configurationGrails(spring-amqp) - 通过 XML 配置使用 SSL 连接 RabbitMQ
【发布时间】:2018-07-16 09:59:56
【问题描述】:

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

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

【问题讨论】:

  • 你为什么在这里使用 Spring XD 的类? spring-rabbit jar 中有一个RabbitConnectionFactoryBean。打开调试日志以查看它是否有帮助 - 更好的是,至少升级到 1.7.5,我们在连接时添加了一些诊断。
  • 我已经尝试过使用 org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean,但我得到了完全相同的错误。当我升级到 1.7.5.RELEASE 时,我得到不同的错误: 原因:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.cache.config.internalCacheAdvisor”的bean时出错:bean初始化失败;嵌套异常是 java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object;
  • 1.7.5 需要更新版本的 spring-framework jar (4.3.13)
  • 我一直在玩依赖并添加了spring-core:4.3.13。之后我仍然遇到同样的错误。我正在使用grails 2.5.6(由于其他插件依赖项,我不能比这更高),它是基于spring 4.1.9 构建的。正如我所看到的,我认为我将使用不同版本的 jar 加倍,并且我怀疑应用了错误的 jar。我不知道是否可以这样工作。看起来grails 2.5.6 我只能达到spring-rabbit:1.4.6 因为更高的版本需要高于4.1.9 的弹簧版本(我坚持使用)。
  • 我已启用调试日志记录,但我又回到了原点。以下是我得到的一些错误相关日志:textuploader.com/dh4i6

标签: xml ssl grails config spring-amqp


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多