通过 WebSocket 协议为 Stomp 使用代理

Use proxy for Stomp over WebSocket protocol

我在 java 中使用基于 WebSocket 协议的 Stomp 处理通知消费。 我的问题是通过代理(具有定义的名称和端口)。 我在网上找了很多,但我找不到很多...

此代码运行良好,我设法使用队列并接收消息。不过我在服务器上部署的时候,并没有解析地址,需要通过专用代理强制传递。

public StompSession connect(StompSessionHandler stompSessionHandler) throws ExecutionException, InterruptedException {
    WebSocketStompClient stompClient = initStompClient();
    StompHeaders connectHeaders = configureHeaders();
    return stompClient.connect(configuration.getUrlBroker(), (WebSocketHttpHeaders) null, connectHeaders, stompSessionHandler).get();
}

private WebSocketStompClient initStompClient() {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    container.setDefaultMaxTextMessageBufferSize(configuration.getMaxTextMessageSize());
    WebSocketClient webSocketClient = new StandardWebSocketClient(container);

    WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient);
    webSocketStompClient.setMessageConverter(new MappingJackson2MessageConverter());
    webSocketStompClient.setTaskScheduler(new ConcurrentTaskScheduler());
    webSocketStompClient.setInboundMessageSizeLimit(configuration.getMaxTextMessageSize());
    return webSocketStompClient;
}

private StompHeaders configureHeaders() {
    StompHeaders headers = new StompHeaders();
    headers.setLogin(configuration.getLogin());
    headers.setPasscode(configuration.getPassword());
    headers.setHeartbeat(new long[]{configuration.getHeartbeatOut(), configuration.getHeartbeatIn()});
    headers.setAcceptVersion(configuration.getAcceptVersion());
    return headers;
}

你有线索吗?

提前致谢。

代理可以在JVM的系统属性中定义:

System.setProperty("http.proxyHost", proxyConfiguration.getHost());
System.setProperty("http.proxyPort", valueOf(proxyConfiguration.getPort()));
System.setProperty("https.proxyHost", proxyConfiguration.getHost());
System.setProperty("https.proxyPort", valueOf(proxyConfiguration.getPort()));