Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSocketMessageBroker
- @EnableScheduling
- class StompConfig : AbstractWebSocketMessageBrokerConfigurer() {
- override fun configureMessageBroker(registry: MessageBrokerRegistry) {
- registry.apply {
- setApplicationDestinationPrefixes("/app")
- enableStompBrokerRelay("/topic")
- }
- }
- override fun registerStompEndpoints(registry: StompEndpointRegistry) {
- registry.addEndpoint("/").setAllowedOrigins("*").withSockJS()
- }
- }
- @Controller
- class Controller(private val amqpTemplate: AmqpTemplate) {
- @Scheduled(fixedDelay = 2000)
- fun send() {
- amqpTemplate.convertAndSend("amq.topic", "my-topic", "message")
- }
- }
- spring:
- rabbitmq:
- port: 15674
- username: user
- password: password
- function connect() {
- socket = new SockJS(uri);
- client = Stomp.over(socket as any);
- client.connect({} as any, frame => {
- client.subscribe("/topic/my-topic", message => {
- console.log(message);
- });
- });
- }
Add Comment
Please, Sign In to add comment