简体   繁体   中英

springboot webflux couchbase API not showing results

I am developing a springboot reactive API to fetch updated results from a couchbase database. I have a N1QL based repository as shown below.

@Repository
@N1qlPrimaryIndexed
public interface LocationDataRepository extends ReactiveCrudRepository<LocationData,String> {

   @Query("#{#n1ql.selectEntity} where  userID=$1 and dataType = $2")
   Flux<LocationData> findByUserIDAndDataType(String userID,String dataType);
}

And my restful webcontroller method is given below.

 @Autowired
    LocationDataRepository locationDataRepository;
    @GetMapping(value="/LocationUpdates", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<LocationData> findLatestLocations(@RequestParam("userID") String userID){
      String dataType = "location";
      return Flux.interval(Duration.ofSeconds(1)).flatMap(X -> locationDataRepository.findByUserIDAndDataType(userID,dataType));
}

My problem is, when I hit this endpoint from browser or postman it does not show any results, but keep refreshing. How ever I was able to save data using the LocationRepository. I can't figure out what is the issue here. Can anyone help me on this? Thank you.

Make sure you have spring-data-couchbase 4.0.1 or later. @Query was only recently implemented. Otherwise it will generate the query itself, which may or may not be what you want. If you execute that query in the Couchbase Web Console, with the appropriate userID and dataType, do you get data back? If you change the produces to MediaType.APPLICATION_JSON_VALUE, does it show in the browser?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM