Java:Reactive Streams简单介绍

       Reactive Streams是一套规范,它为非阻塞带背压的异步流处理提供了一套标准。这套API主要提供了4个接口。它针对不同的开发语言都提供了API,为了讲解方便,下面主要以java为例进行介绍。
以下是Reactive Streams官方提供的java API接口:

<dependency>
    <groupId>org.reactivestreams</groupId>
    <artifactId>reactive-streams</artifactId>
    <version>1.0.3</version>
</dependency>

package org.reactivestreams;

public interface Publisher<T> {

    public void subscribe(Subscriber<? super T> s);
}
package org.reactivestreams;

public interface Subscriber<T> {

    public void onSubscribe(Subscription s);

    public void onNext(T t);

    public void onError(Throwable t);

    public void onComplete();
}
package org.reactivestreams;

public interface Subscription {

    public void request(long n);

    public void cancel();
}
package org.reactivestreams;

public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}

java从JDK9开始,也提供了一套功能上完全等同于Reactive Streams的接口,java.util.concurrent.Flow

java.util.concurrent.Flow.Processor<T,R>
java.util.concurrent.Flow.Publisher<T>
java.util.concurrent.Flow.Subscriber<T>
java.util.concurrent.Flow.Subscription

Reactive Streams官方介绍文档如下:
https://www.reactive-streams.org/
Reactive Streams针对不同开发语言提供的API:
https://github.com/reactive-streams


由于Reactive Streams只是一套API接口规范,如果要实际使用它,需要对它进行实现。现在,很多项目对Reactive Streams进行了实现,其中比较有名的是ReactiveX、Project Reactor等,它们都提供了针对多种开发语言的实现版本。

ReactiveX的主要实现类:

io.reactivex.rxjava3.core.Flowable0..N flows, supporting Reactive-Streams and backpressure
io.reactivex.rxjava3.core.Observable0..N flows, no backpressure
io.reactivex.rxjava3.core.Singlea flow of exactly 1 item or an error
io.reactivex.rxjava3.core.Completablea flow without items but only a completion or error signal
io.reactivex.rxjava3.core.Maybea flow with no items, exactly one item or an error

Reactor的Publisher实现类:

reactor.core.publisher.Fluxan Asynchronous Sequence of 0-N Items
reactor.core.publisher.Monoan Asynchronous 0-1 Result

它们的主要资料可以在如下网址上查到:

ReactiveX:
http://reactivex.io/
https://github.com/ReactiveX/RxJava

Project Reactor:
https://projectreactor.io/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值