The issue I am facing:
Whatever I try through various tutorials on using Spring Reactive (WebFlux) REST API's, I am unable to get it to work. When I initially call my endpoint, I am able to get the results from the MongoDB collection. However, whenever I make an update to a document entry, or add a new document, it is not updated in through the text-event-stream. Each time I have to call the endpoint again to get new results.
The setup:
Currently I have the following setup:
- Spring Cloud Gateway (behind which I run various )
- Spring Boot Service containing RestControllers (calling this the main service)
I am using Spring Webflux, Spring Cloud Gateway and Spring ReactiveMongoRepository.
The dependencies included pom.xml for the Spring Boot main service:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
The code for the ReactiveMongoRepository:
@Repository
public interface TestRepository extends ReactiveMongoRepository<TestIntegration, String> {
@Query(("{'userId': ?0}"))
Flux<TestIntegration> findbyUserId(String userId);
}
The code for the rest Controller:
@GetMapping(value = "main/integrations", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<TestIntegration> retrieveIntegrations(ServerWebExchange exchange) {
return testRepository.findAll();
}
According to every tutorial/guideline I have read, this should be working according to this approach. Has anyone experienced this as well or might be able to assist in the matter? Currently stuck on this for days...