Created
September 28, 2021 00:37
-
-
Save exaucae/f0b3643a32f1f9971ea0045d47f47bc8 to your computer and use it in GitHub Desktop.
Websocket over Stomp Java client config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package client.websocket.adapter.parent; | |
import com.google.gwt.user.client.Window; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import org.springframework.messaging.simp.stomp.StompCommand; | |
import org.springframework.messaging.simp.stomp.StompHeaders; | |
import org.springframework.messaging.simp.stomp.StompSession; | |
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; | |
@SuppressWarnings("NullableProblems") | |
abstract class AbstractWebSocketClientAdapter extends StompSessionHandlerAdapter { | |
private final Logger logger = LogManager.getLogger(AbstractWebSocketClientAdapter.class); | |
protected abstract String getEndpoint(); | |
protected abstract String getTopic(); | |
protected abstract String getDestination(); | |
@Override | |
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) { | |
logger.error("Exception received: ", exception); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package client.websocket.config; | |
import lombok.RequiredArgsConstructor; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.messaging.converter.MappingJackson2MessageConverter; | |
import org.springframework.messaging.simp.stomp.StompClientSupport; | |
import org.springframework.web.socket.client.WebSocketClient; | |
import org.springframework.web.socket.client.standard.StandardWebSocketClient; | |
import org.springframework.web.socket.messaging.WebSocketStompClient; | |
@Configuration | |
@RequiredArgsConstructor(onConstructor_ = @Autowired) | |
public class StompClientConfig extends StompClientSupport { | |
@Bean | |
public WebSocketStompClient getStompClient() { | |
WebSocketClient client = new StandardWebSocketClient(); | |
WebSocketStompClient stompClient = new WebSocketStompClient(client); | |
stompClient.setMessageConverter(new MappingJackson2MessageConverter()); | |
return stompClient; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment