-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.eastrobot</groupId> | ||
<artifactId>kbase-heap</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kbase-stack-sse</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
20 changes: 20 additions & 0 deletions
20
kbase-stack-sse/src/main/java/com/ibothub/heap/sse/SseApplication.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* powered by https://ekozhan.com | ||
*/ | ||
package com.ibothub.heap.sse; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">eko.zhan</a> | ||
* @version v1.0 | ||
* @since 2024/12/11 13:59 | ||
*/ | ||
@SpringBootApplication | ||
public class SseApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SseApplication.class, args); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
kbase-stack-sse/src/main/java/com/ibothub/heap/sse/controller/HelloController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* powered by https://ekozhan.com | ||
*/ | ||
package com.ibothub.heap.sse.controller; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import org.springframework.http.codec.ServerSentEvent; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">eko.zhan</a> | ||
* @version v1.0 | ||
* @since 2024/12/11 14:08 | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/v1/sse") | ||
public class HelloController { | ||
|
||
@GetMapping("/events") | ||
public Flux<ServerSentEvent<String>> getEvents() { | ||
return Flux.interval(Duration.ofSeconds(1)) | ||
.map(sequence -> ServerSentEvent.<String>builder() | ||
.id(String.valueOf(sequence)) | ||
.event("message") | ||
.data("Event #" + sequence + " at " + LocalDateTime.now()) | ||
.build()); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
logging.level.root=debug |
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