简体   繁体   中英

Use proxy for Stomp over WebSocket protocol

I work on notification consumption with Stomp over WebSocket protocol in java. My problem is to go through a proxy (with defined name and port). I've looked a lot on the internet, but I can't find much...

This code works very well, I manage to consume the queue and receive messages. Nevertheless, when I deploy on server, it does not solve the address, it is necessary to pass imperatively by the dedicated proxy.

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;
}

Do you have any leads?

Thank you in advance.

Le proxy peut se définir dans les propriétés système de la 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()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM