Java Spring STOMP : Set broker IP

标签 java spring stomp spring-websocket

我有一个使用 Spring 的 Java 应用程序,该应用程序使用 Websocket,只要 RabbitMQ 与 tomcat 在同一台机器上运行,它就可以正常工作。

如何设置 RabbitMQ 的 IP?我正在阅读文档,但没有找到它。

我当前的配置与 one in the documentation 非常相似

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:websocket="http://www.springframework.org/schema/websocket"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/websocket
        http://www.springframework.org/schema/websocket/spring-websocket.xsd">

    <websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/portfolio">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:simple-broker prefix="/topic, /queue"/>
    </websocket:message-broker>

</beans>

如何设置IP?

最佳答案

您好,您正在使用简单的代理(< websocket:simple-broker prefix="/topic, /queue"/> )。尝试使用以下设置:

<websocket:message-broker application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/ws">
      <websocket:sockjs/>
    </websocket:stomp-endpoint>
     <websocket:stomp-broker-relay prefix="/topic"
           relay-host="${websocket.relay.host}" relay-port="61613" client-login="user" client-passcode="passwd" system-login="user" system-passcode="passwd"
           heartbeat-send-interval="20000" heartbeat-receive-interval="20000"/>
</websocket:message-broker>

此配置将帮助您添加 ip。您可能还需要添加入站和出站 channel 配置,因为默认 channel 是一个。在单个 channel 的负载下,响应会非常慢。 在 <websocket:message-broker> and </websocket:message-broker> 之间插入以下代码片段标签:

<websocket:client-inbound-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:client-inbound-channel>
<websocket:client-outbound-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:client-outbound-channel>
<websocket:broker-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:broker-channel>

此外,您还需要添加登录凭据,以防您的rabbitmq服务器与应用程序不同。为此,您需要更改配置文件。您可以在 RabbitMQ 文档中获取此内容

关于Java Spring STOMP : Set broker IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34504410/

相关文章:

java - 是否有可以从 Hudson/Jenkins 获取工件的 Ant 任务?

java - 启动 slf4j 包无法在 felix 上启动

java - Spring Boot 2 |非常基本的依赖注入(inject)@Autowired问题

message - 如何将对象消息从 perl 传递到 JMS

java - JUNIT 条件测试可能吗?

java - Android + Dozer 抛出 IllegalArgumentException

java - Spring 配置 : Unable to locate Spring NamespaceHandler

spring - junit 每行执行两次

java - RabbitMQ 和 Spring : how to get all subscriptions

stomp - Spring Stomp @SubscribeMapping 用于用户目标