当前位置: 首页 > 知识库问答 >
问题:

为IBM cloud app的RabbitMq连接问题撰写

陈霄
2023-03-14

我在IBM云中创建了一个compose for RabbitMq实例,并通过配置服务器应用程序上的服务绑定使用它。这是我的<code>应用程序。yaml定义了以下属性以连接到compose for rabbitmq服务器:

 spring:
 profiles: config-monitor
 cloud:
     bus:
         enabled: true
 rabbitmq:
      addresses: amqps://USERNAME:PASSWORD@portal-ssl12-36.bmix-xxxxxxxxxxxxxxxx.composedb.com:58288/vhost-xxxxxxxxxxxxxxxxxxxxxxxxxx

此外,通过服务绑定,环境变量用RabbitMQ的VCAP凭证进行了更新。

Maven依赖关系:

 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-config-monitor</artifactId>
     <version>1.4.3.RELEASE</version>
 </dependency>
 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
     <version>1.3.4.RELEASE</version>
 </dependency>

问题是在启动时,我得到RabbitMq服务的连接异常:

o.s.amqp.rabbit.core.RabbitAdmin : 未能声明交换: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continue...

c.r.c.impl.ForgivingExceptionHandler:发生意外的连接驱动程序错误java.net.SocketException:Socket关闭

如下所示:

2018-09-24 17:51:50.646 ERROR 19140 --- [.46.29.90:58547] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured
java.net.SocketException: Socket Closed
 at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_121]
 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_121]
 at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_121]
 at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_121]
 at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_121]
 at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_121]
 at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_121]
 at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571) ~[amqp-client-4.0.3.jar:4.0.3]
 at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
2018-09-24 17:51:50.647 DEBUG 19140 --- [           main] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing...
org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
 at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:74) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:371) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.amqp.rabbit.core.RabbitAdmin.declareExchange(RabbitAdmin.java:157) ~[spring-rabbit-1.7.4.RELEASE.jar:na]
 at org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.declareExchange(RabbitExchangeQueueProvisioner.java:412) [spring-cloud-stream-binder-rabbit-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
 at org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.provisionProducerDestination(RabbitExchangeQueueProvisioner.java:90) [spring-cloud-stream-binder-rabbit-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
 at org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.provisionProducerDestination(RabbitExchangeQueueProvisioner.java:58) [spring-cloud-stream-binder-rabbit-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
 at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:110) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:57) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.cloud.stream.binder.AbstractBinder.bindProducer(AbstractBinder.java:152) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:124) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.cloud.stream.binding.BindableProxyFactory.bindOutputs(BindableProxyFactory.java:238) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.cloud.stream.binding.OutputBindingLifecycle.start(OutputBindingLifecycle.java:57) [spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
 at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
 at aa.ct.fly.config.server.ConfigServer.main(ConfigServer.java:25) [classes/:na]
Caused by: java.util.concurrent.TimeoutException: null
 at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:372) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:297) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:909) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859) ~[amqp-client-4.0.3.jar:4.0.3]
 at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799) ~[amqp-client-4.0.3.jar:4.0.3]
 at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:352) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

我还没有任何其他特殊代码来创建交换/队列等。

知道为什么它会在部署在ibm-cloud中的应用程序和同样由ibm-cloud提供的Rabbitmq服务之间的连接问题时失败吗?

共有1个答案

封德华
2023-03-14

Spring Boot使用amqp协议连接到RabbitMQ,而IBM上的Compose服务通过HAProxy公开为amqps。

在我的例子中,我通过创建一个@Configuration bean直接在rabbitConnectionFactory上更改了连接URI:

@Configuration
@EnableRabbit
public class MessagingConfiguration {

    @Bean
    public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config) throws Exception {

        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
        connectionFactory.getRabbitConnectionFactory().setUri(RABBITMQ_ADDRESS);

        return connectionFactory;

    }

}

还可以在application.yml文件上使用VCAP变量,并使用Spring Boot @Value注释在配置bean上注入。

 类似资料:
  • 问题内容: 我正在运行一个简单的rest应用程序,并在docker容器/ docker-compose中运行。我相信,必须使用Spring Boot才能访问。但是,它会引发错误: 我的代码在这里。 问题答案: 由于在链接中使用别名,因此必须使用与别名相同的主机名来访问容器。因此,您可以执行以下一项操作, 在您的Spring Boot应用程序中使用http:// localhost:6379 而不是

  • 我让RabbitMQ在CloudFoundry中运行,并尝试从本地运行的配置服务器进行连接,下面是在应用程序中配置的内容。yml文件 抛出以下启动异常 下面是pom.xml的依赖关系 我可以使用应用程序中提供的信息连接到控制台。yml但不确定为什么会抛出TimeoutException,任何输入都会非常有用,

  • 问题内容: 如果我在闲置了一段时间后启动应用程序,那么我曾经遇到以下错误。(我正在使用Spring + Hibernate + MySQL作为DB) 我通过将以下内容添加到我的servlet-context.xml中解决了这个问题。 我在这里问了这个问题,这个问题是解决方案所特有的。我需要知道为什么会遇到这个错误。 我尝试了上面链接中提供的第一个选项(使用autoReconnect = true配

  • 在连接jstatd和visualvm时遇到了一些问题。以下是我设置的详细信息: 杰斯塔德。政策 叫做与 牵引端口 港口又好又开放 正在运行的应用程序是在vmware上运行的,尽管可以毫无问题地访问该应用程序。 如果有人对连接visualvm有任何想法,那就太好了。

  • 我在CentOS7(confluent)上安装了Apache Kafka,正试图以分布式模式运行filestream Kafka connect,但收到以下错误: 现在可以通过更新workers.properties(如http://docs.confluent.io/current/connect/userguide.html#connect-userguide-distributed-conf

  • 我创建了一个测试帐户来开始使用BrowserStack。我关注了以下页面:在Browserstack Automate上运行量角器测试,这真的很有帮助。 现在我得到: 这是什么意思?我没有任何请求。我只是打开一个页面,点击一个元素,就这样了。