{"id":18559057,"url":"https://github.com/linux-china/reactive-demo","last_synced_at":"2025-04-10T02:30:38.356Z","repository":{"id":46897588,"uuid":"73530590","full_name":"linux-china/reactive-demo","owner":"linux-china","description":"Reactive Demo with Reactor, RxJava and reactive-stream","archived":false,"fork":false,"pushed_at":"2024-12-23T05:57:25.000Z","size":533,"stargazers_count":19,"open_issues_count":17,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:51:13.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linux-china.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-11-12T04:04:45.000Z","updated_at":"2025-02-21T23:15:04.000Z","dependencies_parsed_at":"2023-02-16T16:16:25.790Z","dependency_job_id":"b27d4d82-4fd5-490c-aa91-f742f8de31e4","html_url":"https://github.com/linux-china/reactive-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Freactive-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Freactive-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Freactive-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Freactive-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linux-china","download_url":"https://codeload.github.com/linux-china/reactive-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144157,"owners_count":21054876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:41:56.885Z","updated_at":"2025-04-10T02:30:37.981Z","avatar_url":"https://github.com/linux-china.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Reactive Programming\n====================\n\n![Reactive Landscape](reactive-landscape.png)\n\n### Demos\nPlease use JDK 11 to run all demos.\n\n* Java 9 Flow\n* RxJava 1.x\n* RxJava 2.x\n* Reactor 3.2.x\n* RSocket\n* Reactive API for Cache, Messaging\n* Reactive with HTTP: webclient \u0026 retrofit\n* Kotlin\n* Webflux\n* Kotlin Coroutines \u0026 Flow\n* Reaktive: Kotlin multi-platform implementation of Reactive Extensions\n\n### Glossary\n\n* reactive: 响应的，响应式的\n* streaming: 流式的\n* asynchronous: 异步的\n* non-blocking: 非阻塞的\n* Observable 可观测的\n* Single: 单个的\n* Flux: 流量\n* Mono: 单一的\n\n### Reactive Operation\n\n* Creation\n* Combine\n* transform(map,flatMap)\n* Filter\n* Mathematical and Aggregate Operators\n* Utility Operators\n* Conditional and Boolean Operators\n* Error Handling\n\n##### reactive stream\n\n* Publisher: A Publisher is a provider of a potentially unbounded number of sequenced elements, publishing them according to the demand received from its Subscriber(s).\n* Subscriber: Receive call to onSubscribe(Subscription) once after passing an instance of Subscriber to Publisher.subscribe(Subscriber).\n* Subscription: A Subscription represents a one-to-one lifecycle of a Subscriber subscribing to a Publisher, use subscription.request() method to request items.\n* Processor:  Processor represents a processing stage—which is both a Subscriber and a Publisher and obeys the contracts of both\n\n### ReactiveX\n\n* Observable\n* Operators\n* Single\n* Subject\n* Scheduler\n\n### Java 9\n\nhttps://www.baeldung.com/java-9-reactive-streams\n\n* java.util.concurrent.Flow: Interrelated interfaces and static methods for establishing flow-controlled components\n* SubmissionPublisher: publisher\n\n##### RxJava\n\n* Observable: This class provides methods for subscribing to the Observable as well as delegate methods to the various Observers.\n* Single: Reactive Pattern for a single value response\n* Observer: Provides a mechanism for receiving push-based notifications\n* Subscriber: Provides a mechanism for receiving push-based notifications from Observables, and permits manual unsubscribing from these Observables.\n\n#### RxJava 2 \u0026 3\n\nRxJava 2 features several base classes you can discover operators on:\n\n* io.reactivex.Flowable: 0..N flows, supporting Reactive-Streams and backpressure\n* io.reactivex.Observable: 0..N flows, no backpressure,\n* io.reactivex.Single: a flow of exactly 1 item or an error,\n* io.reactivex.Completable: a flow without items but only a completion or error signal,\n* io.reactivex.Maybe: a flow with no items, exactly one item or an error.\n* Notification: Represents the reactive signal types: onNext, onError and onComplete and holds their parameter values (a value, a Throwable, nothing)\n* Subject: Represents an Observer and an Observable at the same time, allowing multicasting events from a single source to multiple child Observers\n\n##### Reactor\n\n* Flux: A Reactive Streams {@link Publisher} with rx operators that emits 0 to N elements, and then completes  (successfully or with an error).\n* Mono: A Reactive Streams {@link Publisher} with basic rx operators that completes successfully by emitting an element, or with an error.\n* FluxSink: next/error/complete sink to push data to flux\n* FluxProcessor: processor\n* Signal: A domain representation of a Reactive Stream signal. There are 4 distinct signals and their possible sequence is defined as such: onError | (onSubscribe onNext* (onError | onComplete)?)\n\n#### Akka Stream\n\nStream process: Source -\u003e Flow -\u003e Sink\n\n* Source： A processing stage with exactly one output, emitting data elements whenever downstream processing stages are ready to receive them.\n* Sink: A processing stage with exactly one input, requesting and accepting data elements possibly slowing down the upstream producer of elements\n* Flow: A processing stage which has exactly one input and output, which connects its up- and downstreams by transforming the data elements flowing through it.\n* Source.single: Stream a single object\n\nOperators: https://doc.akka.io/docs/akka/2.5/stream/operators/index.html#source-operators\n\n### Kafka Streams\n\nhttps://kafka.apache.org/documentation/streams/\n\n* Topology: A topology is an acyclic graph of sources, processors, and sinks.\n* KafkaStreams: A Kafka client that allows for performing continuous computation on input coming from one or more input topics and sends output to zero, one, or more output topics.\n* KStream: an abstraction of a \u003ci\u003erecord stream\u003c/i\u003e of eyValue pairs\n\n### Kafka Reactor\n\nhttps://projectreactor.io/docs/kafka/release/reference/\n\n* KafkaSender: publishing messages to Kafka\n* KafkaReceiver: consuming messages from Kafka\n\n### RxJava VS Reactor\n\n* RxJava诞生早，使用广泛，尤其在Netflix产品中\n* Reactor和Spring整合密切\n* 在Java 8支持方面，Reactor基于Java 8，而RxJava是自己的API\n* RxJava的模型在其他语言都有实现，如果你用多语言的场景化，RxJava的模型更好一些，如Angular等\n\nhttps://www.nurkiewicz.com/2019/02/rxjava-vs-reactor.html\n\n### Kotlin Extension\n\n* https://github.com/ReactiveX/RxKotlin\n* https://github.com/reactor/reactor-kotlin-extensions\n\n### BlockHound\nBlockHound(block代码猎犬)是一个Java agent，主要检测非阻塞线程中的同步调用。 我们常见的同步方法如下：\n\n* java.lang.Thread:  sleep, yield, onSpinWait\n* java.lang.Object: wait\n* java.io.RandomAccessFile: read0, readBytes, write0, writeBytes\n* java.io.FileInputStream: read0, readBytes\n* java.io.FileOutputStream: write, writeBytes\n* java.net.Socket: connect\n* java.net.DatagramSocket: connect\n* java.net.PlainDatagramSocketImpl: connect0, peekData, send\n* java.net.PlainSocketImpl: socketAccept\n* java.net.SocketInputStream: socketRead0\n* java.net.SocketOutputStream: socketWrite0\n* sun.misc.Unsafe: park\n* jdk.internal.misc.Unsafe: park\n* java.lang.ProcessImpl: forkAndExec\n* java.lang.UNIXProcess: forkAndExec\n\n\n凡是涉及到以上代码，都是同步调用，需要注意，尤其是使用wait和notifyAll来设计线程协调。\n\n* java.util.concurrent.CountDownLatch: await\n\n\n### Exception handling\n\nReactor for handling error: doOnError, onErrorMap, onErrorReturn, and onErrorResume\n\n* doOnError: executed when an error is thrown and hasn't been caught\n* onErrorMap: used to map an error into another error. As it's only being mapped, the error is still thrown\n* onErrorReturn: set a fallback value that will be returned if error is thrown. The next operator in the chain will get the fallback value instead of error.\n* onErrorResume: set a fallback method that will be executed if error is thrown. The next operator in the chain will get the result of the fallback method instead of error.\n\n###  References\n\n* http://www.reactive-streams.org: Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure\n* http://reactivex.io: An API for asynchronous programming with observable streams\n* http://projectreactor.io: Reactor is a second-generation Reactive library for building non-blocking applications on the JVM based on the Reactive Streams Specification\n* https://tech.io/playgrounds/929/reactive-programming-with-reactor-3/content/Intro\n* http://reactivex.io/documentation/operators.html: reactive operations\n* https://dzone.com/articles/functional-amp-reactive-spring-along-with-netflix: Functional and Reactive Spring with Reactor and Netflix OSS\n* RxJava2 响应式编程介绍: https://zouzhberk.github.io/rxjava-study/\n* Reactive Streams: https://github.com/reactive-streams/reactive-streams-jvm/blob/v1.0.2/README.md#specification\n* RSocket: http://rsocket.io/\n* Reactor Netty: http://projectreactor.io/docs/netty/release/reference/index.html\n* Reactor Testing: http://projectreactor.io/docs/core/release/reference/index.html\n* RxJava Extensions: https://github.com/akarnokd\n* Reaktive — a multiplatform library for reactive Kotlin: https://github.com/badoo/Reaktive https://badootech.badoo.com/reaktive-a-multiplatform-library-for-reactive-kotlin-android-ios-77b6ff25adb1\n* Reactive Spring Boot: https://learning.oreilly.com/live-training/courses/reactive-spring-boot/0636920371410/\n* Reactive marble diagram generator: https://bitbucket.org/achary/rx-marbles/  https://medium.com/@jshvarts/read-marble-diagrams-like-a-pro-3d72934d3ef5\n* Animated playground for Rx Observables: https://rxviz.com/\n* SmallRye Mutiny: a reactive programming library https://github.com/smallrye/smallrye-mutiny\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Freactive-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinux-china%2Freactive-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Freactive-demo/lists"}