【问题标题】:Failed to connect to Amazon MQ with spring-boot 2 and Stomp无法使用 spring-boot 2 和 Stomp 连接到 Amazon MQ
【发布时间】:2020-07-07 22:21:06
【问题描述】:

我正在使用 Spring boot 2、Stomp 和 Amazon MQ 构建 WebSocket 应用程序。

但是我无法连接到 Amazon MQ 代理。我收到Failed to connect: connection timed out 错误。

我的 WebSocket 配置:

@Configuration
@RequiredArgsConstructor
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    private final ActiveMQProperties properties;

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/")
                .setAllowedOrigins("*")
                .withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/topic")
                .setAutoStartup(true)
                .setRelayPort(61614)
                .setRelayHost(properties.getBrokerUrl())
                .setClientLogin(properties.getUser())
                .setClientPasscode(properties.getPassword())
                .setSystemLogin(properties.getUser())
                .setSystemPasscode(properties.getPassword())
               .setTcpClient(createClient());
    }

    private TcpOperations<byte[]> createClient(){
        return new ReactorNettyTcpClient<>((client) -> client
//                .host(properties.getBrokerUrl())
//                .port(61614)
                .addressSupplier(this::getAddress)
                .secure(), new StompReactorNettyCodec());

    }

    private SocketAddress getAddress() {
        try {
            InetAddress address = InetAddress.getByName(properties.getBrokerUrl());
            SocketAddress socketAddress = new InetSocketAddress(address, 61614);
            return socketAddress;
        } catch (UnknownHostException e) {
            log.error(e);
        }
        return null;
    }

日志

2020-03-27 16:21:19.419  WARN 49890 --- [ealth-indicator] o.s.boot.actuate.jms.JmsHealthIndicator  : Connection failed to start within 5 seconds and will be closed.
2020-03-27 16:21:39.156  INFO 49890 --- [ient-loop-nio-1] o.s.m.s.s.StompBrokerRelayMessageHandler : TCP connection failure in session _system_: Failed to connect: connection timed out: {my-aws-url}:61614
io.netty.channel.ConnectTimeoutException: connection timed out: {my-aws-url}:61614
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ~[netty-transport-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-transport-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.45.Final.jar:4.1.45.Final]
    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_241]
2020-03-27 16:21:39.156 DEBUG 49890 --- [ient-loop-nio-1] org.springframework.web.SimpLogging      : Cleaning up connection state for session _system_

【问题讨论】:

    标签: amazon-web-services spring-boot activemq stomp amazon-mq


    【解决方案1】:

    需要为 AWS MQ 代理配置分配安全组。当您不选择任何安全组时,它将使用默认安全组。 因此,您的 IP 必须添加到使用的安全组中。 然后您可以访问 MQ 管理 UI 或队列。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
    【解决方案2】:

    我认为您在安全组/NACL 中缺少一个条目以允许端口 61614 上的流量。我还将检查客户端主机是否可以使用 traceroute 访问代理主机。解决其中任何一个问题都应该解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-18
      • 2023-02-10
      • 1970-01-01
      • 2020-06-16
      • 2023-02-06
      • 2021-09-25
      • 1970-01-01
      • 2017-10-05
      相关资源
      最近更新 更多