Skip to content

Commit

Permalink
feat(sse): sse samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoz committed Dec 11, 2024
1 parent 1c91f8d commit d6903ce
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
28 changes: 28 additions & 0 deletions kbase-stack-sse/pom.xml
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>
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);
}
}
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());
}

}
1 change: 1 addition & 0 deletions kbase-stack-sse/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logging.level.root=debug
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<module>kbase-stack-xxl</module>
<module>kbase-stack-screw</module>
<module>kbase-stack-database</module>
<module>kbase-stack-sse</module>
</modules>
<packaging>pom</packaging>

Expand Down

0 comments on commit d6903ce

Please sign in to comment.