{"id":26031715,"url":"https://github.com/apache/pulsar-client-reactive","last_synced_at":"2025-04-06T19:12:09.848Z","repository":{"id":58976946,"uuid":"533870035","full_name":"apache/pulsar-client-reactive","owner":"apache","description":"Reactive client for Apache Pulsar","archived":false,"fork":false,"pushed_at":"2025-02-12T12:30:26.000Z","size":719,"stargazers_count":61,"open_issues_count":17,"forks_count":19,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-04-03T04:17:05.011Z","etag":null,"topics":["apache-pulsar","backpressure","project-reactor","pulsar","reactive-streams"],"latest_commit_sha":null,"homepage":"https://pulsar.apache.org/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":"CONTRIBUTING.adoc","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-07T17:29:14.000Z","updated_at":"2025-03-16T14:34:27.000Z","dependencies_parsed_at":"2023-11-06T08:44:39.561Z","dependency_job_id":"9af8bc3c-9108-45e8-b424-447c6413ef0f","html_url":"https://github.com/apache/pulsar-client-reactive","commit_stats":{"total_commits":120,"total_committers":7,"mean_commits":"17.142857142857142","dds":"0.43333333333333335","last_synced_commit":"cc27d87cc882d06ed55f68eba05a17fa46b6ac83"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fpulsar-client-reactive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fpulsar-client-reactive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fpulsar-client-reactive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fpulsar-client-reactive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/pulsar-client-reactive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"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":["apache-pulsar","backpressure","project-reactor","pulsar","reactive-streams"],"created_at":"2025-03-06T20:44:15.774Z","updated_at":"2025-04-06T19:12:09.827Z","avatar_url":"https://github.com/apache.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"////\n    Licensed to the Apache Software Foundation (ASF) under one\n    or more contributor license agreements.  See the NOTICE file\n    distributed with this work for additional information\n    regarding copyright ownership.  The ASF licenses this file\n    to you under the Apache License, Version 2.0 (the\n    \"License\"); you may not use this file except in compliance\n    with the License.  You may obtain a copy of the License at\n\n      https://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing,\n    software distributed under the License is distributed on an\n    \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n    KIND, either express or implied.  See the License for the\n    specific language governing permissions and limitations\n    under the License.\n////\n= Reactive client for Apache Pulsar\n\n:github: https://github.com/apache/pulsar-client-reactive\n:latest_version: 0.5.10\n\nReactive client for Apache Pulsar which is compatible with the Reactive Streams specification.\nThis uses Project Reactor as the Reactive Streams implementation.\n\n== Getting it\n\n*This library requires Java 8 or + to run*.\n\nWith Gradle:\n\n[source,groovy,subs=\"verbatim,attributes\"]\n----\ndependencies {\n    implementation \"org.apache.pulsar:pulsar-client-reactive-adapter:{latest_version}\"\n}\n----\n\nWith Maven:\n\n[source,xml,subs=\"verbatim,attributes\"]\n----\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n        \u003cartifactId\u003epulsar-client-reactive-adapter\u003c/artifactId\u003e\n        \u003cversion\u003e{latest_version}\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n----\n\n[[pulsar-client-reactive-bom]]\n=== Pulsar Client Reactive BOM\n\nWhile the above dependency is sufficient to obtain the Pulsar Reactive Java client, it is recommended to also use the provided BOM to ensure that all Pulsar dependencies are at the same expected version.\nIn order to use the BOM, the previous directions are modified slightly as follows:\n\nWith Gradle:\n\n[source,groovy,subs=\"verbatim,attributes\"]\n----\ndef pulsarReactiveVersion = '{latest_version}'\n\ndependencies {\n  implementation enforcedPlatform(\"org.apache.pulsar:pulsar-client-reactive-bom:${pulsarVersion}\")\n  implementation 'org.apache.pulsar:pulsar-client-reactive-adapter'\n}\n----\n\nWith Maven:\n\n[source,xml,subs=\"verbatim,attributes\"]\n----\n\u003c!-- in your \u003cproperties\u003e block --\u003e\n\u003cpulsar-reactive.version\u003e{latest_version}\u003c/pulsar-reactive.version\u003e\n\n\u003c!-- in your \u003cdependencyManagement\u003e/\u003cdependencies\u003e block --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n  \u003cartifactId\u003epulsar-client-reactive-bom\u003c/artifactId\u003e\n  \u003cversion\u003e${pulsar-reactive.version}\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n  \u003cscope\u003eimport\u003c/scope\u003e\n\u003c/dependency\u003e\n\n\u003c!-- in your \u003cdependencies\u003e block --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n  \u003cartifactId\u003epulsar-client-reactive-adapter\u003c/artifactId\u003e\n\u003c/dependency\u003e\n----\n\n=== Spring Boot\nWhen using the Spring Boot Pulsar Reactive starter there is no need to directly specify the client dependency as described above because it will be automatically added to dependencies as a transitive dependency of the `spring-boot-starter-pulsar-reactive` dependency.\n\nThe Spring Boot https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-dependency-versions.html[Dependency Version properties] define `pulsar-reactive.version` for controlling the Pulsar Java Reactive client version.\n\nYou can find more information about using Pulsar with Spring Boot in the https://docs.spring.io/spring-boot/reference/messaging/pulsar.html[Spring Boot documentation].\n\nWith Gradle:\n\n[source,groovy,subs=\"verbatim,attributes\"]\n----\n// Alternatively, you can set the `pulsar-reactive.version` property in the `gradle.properties` file.\next['pulsar-reactive.version'] = '{latest_version}'\n\ndependencies {\n  implementation 'org.springframework.boot:spring-boot-starter-pulsar-reactive'\n}\n----\n\nWith Maven:\n\n[source,xml,subs=\"verbatim,attributes\"]\n----\n\u003c!-- in your \u003cproperties\u003e block --\u003e\n\u003cpulsar-reactive.version\u003e{latest_version}\u003c/pulsar-reactive.version\u003e\n\n\u003c!-- in your \u003cdependencies\u003e block --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n  \u003cartifactId\u003espring-boot-starter-pulsar-reactive\u003c/artifactId\u003e\n\u003c/dependency\u003e\n----\n\nNOTE: In both Maven and Gradle cases above, the `pulsar-reactive.version` only needs to be specified when you want to override the version of the client that Spring Boot recommends.\n\n== Usage\n\n=== Initializing the library\n\n==== In standalone application\n\nUsing an existing PulsarClient instance:\n\n[source,java]\n----\nReactivePulsarClient reactivePulsarClient = AdaptedReactivePulsarClientFactory.create(pulsarClient);\n----\n\n=== Sending messages\n\n[source,java]\n----\nReactiveMessageSender\u003cString\u003e messageSender = reactivePulsarClient\n        .messageSender(Schema.STRING)\n        .topic(topicName)\n        .maxInflight(100)\n        .build();\nMono\u003cMessageId\u003e messageId = messageSender\n        .sendOne(MessageSpec.of(\"Hello world!\"));\n// for demonstration\nmessageId.subscribe(System.out::println);\n----\n\n=== Sending messages with cached producer\n\nBy default, a ConcurrentHashMap based cache is used.\nIt's recommended to use a more advanced cache based on Caffeine.\nThe cache will get used as the default implementation when it is on the classpath.\n\nAdding Caffeine based producer cache with Gradle:\n\n[source,groovy,subs=\"verbatim,attributes\"]\n----\ndependencies {\n    implementation \"org.apache.pulsar:pulsar-client-reactive-adapter:{latest_version}\"\n    implementation \"org.apache.pulsar:pulsar-client-reactive-producer-cache-caffeine:{latest_version}\"\n}\n----\n\nAdding Caffeine based producer cache with Maven:\n\n[source,xml,subs=\"verbatim,attributes\"]\n----\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n        \u003cartifactId\u003epulsar-client-reactive-adapter\u003c/artifactId\u003e\n        \u003cversion\u003e{latest_version}\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n        \u003cartifactId\u003epulsar-client-reactive-producer-cache-caffeine\u003c/artifactId\u003e\n        \u003cversion\u003e{latest_version}\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n----\n====\n[small]#When using the xref:pulsar-client-reactive-bom[BOM] the above dependency version numbers can be omitted#\n====\nUsage example of cache\n\n[source,java]\n----\nReactiveMessageSender\u003cString\u003e messageSender = reactivePulsarClient\n        .messageSender(Schema.STRING)\n        .cache(AdaptedReactivePulsarClientFactory.createCache())\n        .topic(topicName)\n        .maxInflight(100)\n        .build();\nMono\u003cMessageId\u003e messageId = messageSender\n        .sendOne(MessageSpec.of(\"Hello world!\"));\n// for demonstration\nmessageId.subscribe(System.out::println);\n----\n\nIt is recommended to use a cached producer in most cases.\nThe cache enables reusing the Pulsar Producer instance and related resources across multiple message sending calls.\nThis improves performance since a producer won't have to be created and closed before and after sending a message.\n\nThe adapter library implementation together with the cache implementation will also enable reactive backpressure for sending messages.\nThe `maxInflight` setting will limit the number of messages that are pending from the client to the broker.\nThe solution will limit reactive streams subscription requests to keep the number of pending messages under the defined limit.\nThis limit is per-topic and impacts the local JVM only.\n\n=== Shaded version of Caffeine\nA version of the provider is available that shades it usage of Caffeine.\nThis is useful in scenarios where there is another version of Caffeine required in your application or if you do not want Caffeine on the classpath.\n\nAdding shaded Caffeine based producer cache with Gradle:\n\n[source,groovy,subs=\"verbatim,attributes\"]\n----\ndependencies {\n    implementation \"org.apache.pulsar:pulsar-client-reactive-adapter:{latest_version}\"\n    implementation \"org.apache.pulsar:pulsar-client-reactive-producer-cache-caffeine-shaded:{latest_version}\"\n}\n----\n\nAdding shaded Caffeine based producer cache with Maven:\n\n[source,xml,subs=\"verbatim,attributes\"]\n----\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n        \u003cartifactId\u003epulsar-client-reactive-adapter\u003c/artifactId\u003e\n        \u003cversion\u003e{latest_version}\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.pulsar\u003c/groupId\u003e\n        \u003cartifactId\u003epulsar-client-reactive-producer-cache-caffeine-shaded\u003c/artifactId\u003e\n        \u003cversion\u003e{latest_version}\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n----\n====\n[small]#When using the xref:pulsar-client-reactive-bom[BOM] the above dependency version numbers can be omitted#\n====\n\n\n=== Reading messages\n\nReading all messages for a topic:\n\n[source,java]\n----\n    ReactiveMessageReader\u003cString\u003e messageReader =\n            reactivePulsarClient.messageReader(Schema.STRING)\n                    .topic(topicName)\n                    .build();\n    messageReader.readMany()\n            .map(Message::getValue)\n            // for demonstration\n            .subscribe(System.out::println);\n----\n\nBy default, the stream will complete when the tail of the topic is reached.\n\n==== Example: poll for up to 5 new messages and stop polling when a timeout occurs\n\nWith `.endOfStreamAction(EndOfStreamAction.POLL)` the Reader will poll for new messages when the reader reaches the end of the topic.\n\n[source,java]\n----\n    ReactiveMessageReader\u003cString\u003e messageReader =\n            reactivePulsarClient.messageReader(Schema.STRING)\n                    .topic(topicName)\n                    .startAtSpec(StartAtSpec.ofLatest())\n                    .endOfStreamAction(EndOfStreamAction.POLL)\n                    .build();\n    messageReader.readMany()\n            .take(Duration.ofSeconds(5))\n            .take(5)\n            // for demonstration\n            .subscribe(System.out::println);\n----\n\n=== Consuming messages\n\n[source,java]\n----\n    ReactiveMessageConsumer\u003cString\u003e messageConsumer=\n        reactivePulsarClient.messageConsumer(Schema.STRING)\n        .topic(topicName)\n        .subscriptionName(\"sub\")\n        .build();\n    messageConsumer.consumeMany(messageFlux -\u003e\n                    messageFlux.map(message -\u003e\n                            MessageResult.acknowledge(message.getMessageId(), message.getValue())))\n        .take(Duration.ofSeconds(2))\n        // for demonstration\n        .subscribe(System.out::println);\n----\n\n=== Consuming messages using a message handler component with auto-acknowledgements\n\n[source,java]\n----\nReactiveMessagePipeline reactiveMessagePipeline =\n    reactivePulsarClient\n        .messageConsumer(Schema.STRING)\n        .subscriptionName(\"sub\")\n        .topic(topicName)\n        .build()\n        .messagePipeline()\n        .messageHandler(message -\u003e Mono.fromRunnable(()-\u003e{\n            System.out.println(message.getValue());\n        }))\n        .build()\n        .start();\n// for demonstration\n// the reactive message handler is running in the background, delay for 10 seconds\nThread.sleep(10000L);\n// now stop the message handler component\nreactiveMessagePipeline.stop();\n----\n\n== License\n\nReactive client for Apache Pulsar is Open Source Software released under the link:www.apache.org/licenses/LICENSE-2.0[Apache Software License 2.0].\n\n== How to Contribute\n\nThe library is Apache 2.0 licensed.\n\nContributions are welcome. Please discuss larger changes on the link:mailto:dev@pulsar.apache.org[Apache Pulsar dev mailing list]. There's a link:CONTRIBUTING.adoc[contributing guide] with more details.\n\n== Bugs and Feature Requests\n\nIf you detect a bug or have a feature request or a good idea for Reactive client for Apache Pulsar, please link:${github}/issues/new[open a GitHub issue].\n\n== Questions\n\nPlease use https://stackoverflow.com/tags/reactive-pulsar[[reactive-pulsar\\]] tag on Stackoverflow. https://stackoverflow.com/questions/ask?tags=apache-pulsar,reactive-pulsar[Ask a question now].\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fpulsar-client-reactive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fpulsar-client-reactive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fpulsar-client-reactive/lists"}