Skip to content

Commit

Permalink
implement websocket infrastructure adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jun 25, 2020
1 parent 3558335 commit 9a736f7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions hr-microservice-hexagonal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<!-- <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId>
</exclusion> </exclusions> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.hr.adapter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import com.example.hr.events.BusinessEvent;
Expand All @@ -11,12 +13,12 @@
*
*/
@Service
public class EventPuslisherAdapter implements EventPushlisher {

public class EventPuslisherWebsocketAdapter implements EventPushlisher {
@Autowired private SimpMessagingTemplate messagingTemplate;

@Override
public void publishEvent(BusinessEvent event) {
// TODO Auto-generated method stub

messagingTemplate.convertAndSend("changes", event);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.hr.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
registry.setApplicationDestinationPrefixes("/ws");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/changes").setAllowedOrigins("*").withSockJS();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
spring.main.banner-mode=off
# REST API URL BASE
# http://localhost:7001/hr/api/v1
# http(s)://localhost:7001/hr/api/v1
server.address=localhost
server.port=7001
server.servlet.context-path=/hr
spring.mvc.servlet.path=/api/v1

# WebSocket URL
# ws://localhost:7001/hr/api/v1/changes

major.version=1
minor.version=0
timestamp=1581420934
Expand Down

0 comments on commit 9a736f7

Please sign in to comment.