[英]Spring boot service in kubernetes always responses with HTTP status 400
[英]To sink in the http responses of a remote service to a publisher
我们的系统接收消息以从远程服务获取数据,然后将其存储到数据库中。 目前,它会打开与数据库的多个连接,以保存每个请求的已获取数据。 我们希望将其转换为具有多个生成器(从远程服务获取数据)和单个使用者的进程,以在数据库中保留数据。 这样做它最多只能保持一个连接来保存数据库中的数据。
我们正在使用带反应器的弹簧靴。 我们希望发布者发布从我们可以订阅的远程服务获取的所有数据,并将这些数据推送到数据库中的200个记录中。
例如,我计划让我们使用代码来使用来自ActiveMQ队列的消息:
public Publisher<Message<RestoreMessage>> restoreMessagesSource() {
return IntegrationFlows
.from(Jms.messageDrivenChannelAdapter(this.connectionFactory)
.destination(RestoreMessage.class.getSimpleName() + "Queue"))
.channel(MessageChannels.queue())
.log(LoggingHandler.Level.DEBUG)
.log()
.toReactivePublisher();
}
在此代码中,来自ActiveMQ qeueu的消息被放入ReactivePublisher中。 这个出版商已经被收录。 这样我们就会混淆队列中的消息。
以类似的方式,我们希望将所有远程API的响应推送到我们可以在一个地方的订户中处理的发布者。
听起来你将有几个Publisher<Message<?>>
并且你想在一个订阅者中使用它们。 因此您可以使用:
/**
* Merge data from {@link Publisher} sequences contained in an array / vararg
* into an interleaved merged sequence. Unlike {@link #concat(Publisher) concat},
* sources are subscribed to eagerly.
* <p>
* <img class="marble" src="doc-files/marbles/mergeFixedSources.svg" alt="">
* <p>
* Note that merge is tailored to work with asynchronous sources or finite sources. When dealing with
* an infinite source that doesn't already publish on a dedicated Scheduler, you must isolate that source
* in its own Scheduler, as merge would otherwise attempt to drain it before subscribing to
* another source.
*
* @param sources the array of {@link Publisher} sources to merge
* @param <I> The source type of the data sequence
*
* @return a merged {@link Flux}
*/
@SafeVarargs
public static <I> Flux<I> merge(Publisher<? extends I>... sources) {
因此,您将把所有资源汇集到一个Flux
并订阅这个。
注意Note
。 .toReactivePublisher()
确实产生了无限的源 ,但根据Jms.messageDrivenChannelAdapter()
它是在侦听器容器中的执行器的特定线程中完成的。 因此,请按原样尝试或使用特定的publishOn()
将每个源包装到Flux
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.