diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 36eaaa1530..5065457c4b 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -60,7 +60,13 @@ - + + + org.projectlombok + lombok + compile + + org.apache.geronimo.specs geronimo-json_1.1_spec diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/Event.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java similarity index 79% rename from spring-reactive-websocket/src/main/java/com/baeldung/Event.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java index 20d678c214..90f83a566f 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/Event.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java new file mode 100644 index 0000000000..3e25e2a29c --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java @@ -0,0 +1,23 @@ +package com.baeldung.reactive.websocket; + +import java.net.URI; +import java.time.Duration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.socket.WebSocketMessage; +import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; +import org.springframework.web.reactive.socket.client.WebSocketClient; + +import reactor.core.publisher.Mono; + +@SpringBootApplication +public class ReactiveJavaClientWebSocket { + public static void main(String[] args) throws InterruptedException { + WebSocketClient client = new ReactorNettyWebSocketClient(); + client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) + .thenMany(session.receive() + .map(WebSocketMessage::getPayloadAsText) + .log()) + .then()) + .block(Duration.ofSeconds(10L)); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java new file mode 100644 index 0000000000..43b5e50387 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.reactive.websocket; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ReactiveWebSocketApplication { + public static void main(String[] args) { + SpringApplication.run(ReactiveWebSocketApplication.class, args); + } +} diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java similarity index 96% rename from spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java index 6729e09273..974def5a91 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java similarity index 98% rename from spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java index 4a548322b3..7f74e714f6 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import org.springframework.web.reactive.socket.WebSocketSession; diff --git a/spring-reactive-websocket/src/main/resources/static/client-websocket.html b/spring-5-reactive/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-websocket/src/main/resources/static/client-websocket.html rename to spring-5-reactive/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-websocket/pom.xml b/spring-reactive-websocket/pom.xml deleted file mode 100644 index 846cece177..0000000000 --- a/spring-reactive-websocket/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - spring-reactive-websocket - 0.0.1-SNAPSHOT - jar - - spring-reactive-websocket - Reactive WebSockets with Spring 5 - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - UTF-8 - UTF-8 - 1.8 - - - - - org.springframework.boot - spring-boot-starter-integration - 2.0.0.M7 - - - org.springframework.boot - spring-boot-starter-webflux - 2.0.0.M7 - - - org.projectlombok - lombok - compile - RELEASE - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java deleted file mode 100644 index f8952d750d..0000000000 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung; - -import java.net.URI; -import java.time.Duration; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.socket.WebSocketMessage; -import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; -import org.springframework.web.reactive.socket.client.WebSocketClient; - -import reactor.core.publisher.Mono; - -@SpringBootApplication -public class ReactiveWebSocketApplication { - public static void main(String[] args) { - SpringApplication.run(ReactiveWebSocketApplication.class, args); - } - - /** - * Spring Reactive WebSocket Client - * **/ - @Bean - CommandLineRunner runner() { - return run -> { - WebSocketClient client = new ReactorNettyWebSocketClient(); - client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) - .thenMany(session.receive() - .map(WebSocketMessage::getPayloadAsText) - .log()) - .then()) - .block(); -// .block(Duration.ofSeconds(10L));//force timeout after given duration - }; - } -}