无法使用被动方法将文档保存到couchbase
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使用被动方法将文档保存到couchbase相关的知识,希望对你有一定的参考价值。
我试图保持调度程序生成的某个日期,然后以流方式通过休息端点读取它们。我有一个非常简单的模型,Feed
只持有uuid和一些文本。我还有一个扩展ReactiveCouchbaseRepository<Feed, String>
的存储库。
当我使用CouchbaseRepository<Feed, String>
时坚持工作。这是我的Feed
:
@Document
public class Feed {
@Id
private String id;
@Field
private String text;
...
和存储库:
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "feed")
public interface FeedRepository extends ReactiveCouchbaseRepository<Feed, String> {
}
以及调度程序:
....
@Autowired
private FeedRepository feedRepository;
@Scheduled(fixedRate = 1000)
public void generate(){
feedRepository.save(new Feed(UUID.randomUUID().toString(), String.valueOf(System.currentTimeMillis())));
...
这是我的终点:
@RestController
public class MainController {
@Autowired
private FeedRepository feedRepository;
@GetMapping(value = "/get/feed/live", produces = "text/event-stream")
public Flux<Feed> getLiveFeeds(){
return feedRepository.findAll();
}
}
当我调用端点时,我得到了这个:
Tue Apr 09 15:12:02 CEST 2019
There was an unexpected error (type=Internal Server Error, status=500).
View feed/all does not exist.
com.couchbase.client.java.error.ViewDoesNotExistException: View feed/all does not exist.
at com.couchbase.client.java.view.ViewQueryResponseMapper$BuildViewResult.call(ViewQueryResponseMapper.java:211)
at com.couchbase.client.java.view.ViewQueryResponseMapper$BuildViewResult.call(ViewQueryResponseMapper.java:185)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:113)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:281)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:216)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Assembly trace from producer [reactor.core.publisher.FluxDefer] :
reactor.core.publisher.Flux.defer(Flux.java:805)
org.springframework.data.repository.util.ReactiveWrapperConverters$RxJava1ObservableToFluxConverter.convert(ReactiveWrapperConverters.java:682)
Error has been observed by the following operator(s):
|_ Flux.defer ⇢ org.springframework.data.repository.util.ReactiveWrapperConverters$RxJava1ObservableToFluxConverter.convert(ReactiveWrapperConverters.java:682)
|_ Flux.map ⇢ org.springframework.http.codec.ServerSentEventHttpMessageWriter.encode(ServerSentEventHttpMessageWriter.java:119)
|_ Mono.doOnError ⇢ org.springframework.http.server.reactive.AbstractServerHttpResponse.writeAndFlushWith(AbstractServerHttpResponse.java:186)
|_ Mono.flatMap ⇢ org.springframework.web.reactive.DispatcherHandler.lambda$handleResult$5(DispatcherHandler.java:175)
|_ Mono.onErrorResume ⇢ org.springframework.web.reactive.DispatcherHandler.handleResult(DispatcherHandler.java:175)
|_ Mono.flatMap ⇢ org.springframework.web.reactive.DispatcherHandler.handle(DispatcherHandler.java:152)
|_ Mono.defer ⇢ org.springframework.web.server.handler.DefaultWebFilterChain.filter(DefaultWebFilterChain.java:119)
|_ Mono.doAfterSuccessOrError ⇢ org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter.filter(HttpTraceWebFilter.java:99)
|_ Mono.flatMap ⇢ org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter.filter(HttpTraceWebFilter.java:82)
|_ Mono.defer ⇢ org.springframework.web.server.handler.DefaultWebFilterChain.filter(DefaultWebFilterChain.java:119)
|_ Mono.defer ⇢ org.springframework.web.server.handler.DefaultWebFilterChain.filter(DefaultWebFilterChain.java:119)
|_ Mono.doOnSuccess ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter.filter(MetricsWebFilter.java:84)
|_ Mono.doOnError ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter.filter(MetricsWebFilter.java:84)
|_ Mono.compose ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter.filter(MetricsWebFilter.java:76)
|_ Mono.defer ⇢ org.springframework.web.server.handler.DefaultWebFilterChain.filter(DefaultWebFilterChain.java:119)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.document.json.JsonObject.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
... 16 more
- 为什么使用反应式存储库时不会保留日期
- 为什么我至少无法获取已使用常规couchbase存储库保留的数据?
谢谢您的帮助。
编辑1:为了坚持下去,有三件事是错误/缺失的:
@EnableReactiveCouchbaseRepositories
失踪(在其中一个答案中指出)- Config没有扩展
AbstractReactiveCouchbaseConfiguration
,而是普通的 最后,电话feedRepository.save(new Feed(UUID.randomUUID().toString(), String.valueOf(System.currentTimeMillis())))
失踪了.subscribe()
。
现在持久的部分工作。抓取仍然有问题。
编辑2
刚刚在调用端点时在日志中发现了这条调试消息:
2019-04-10 16:27:06.467 DEBUG 11172 --- [-computations-3] c.c.client.java.view.ViewRetryHandler : Design document not found, error is {"errors":[{"error":"not_found","reason":"Design document _design/feed not found"}
您似乎忘记使用@EnableReactiveCouchbaseRepositories注释启用反应式存储库:
@SpringBootApplication
@EnableScheduling
@EnableReactiveCouchbaseRepositories
public class ReactiveDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ReactiveDemoApplication.class, args);
}
}
你可以在这里读更多关于它的内容:
看起来您的FeedRepository接口缺少用于执行搜索的视图的名称。
请尝试使用以下视图名称:
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "feed", viewName = "all")
public interface FeedRepository extends ReactiveCouchbaseRepository<Feed, String> {
}
对我来说,它在添加视图名称后起作用。
以上是关于无法使用被动方法将文档保存到couchbase的主要内容,如果未能解决你的问题,请参考以下文章