gpt4 book ai didi

java - Compose 解决来自 IBM 云应用程序的 RabbitMq 连接问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:58 26 4
gpt4 key购买 nike

我已经在 IBM 云中为 RabbitMq 实例创建了一个组合,并且通过我的配置服务器应用程序上的服务绑定(bind)来使用它。我的 application.yaml 定义了以下属性来连接到rabbitmq服务器的compose:

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

此外,通过服务绑定(bind),环境变量已使用 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 : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing...

c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured java.net.SocketException: Socket Closed

如下:

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 服务之间的连接问题而失败吗?

最佳答案

Spring boot 使用 amqp 协议(protocol)连接到 RabbitMQ,而 IBM Cloud 上的 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 注释注入(inject)配置 bean。

关于java - Compose 解决来自 IBM 云应用程序的 RabbitMq 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53154553/

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