{"id":13487633,"url":"https://github.com/hivemq/hivemq-mqtt-client","last_synced_at":"2025-05-14T08:08:39.243Z","repository":{"id":45526521,"uuid":"116057862","full_name":"hivemq/hivemq-mqtt-client","owner":"hivemq","description":"HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support","archived":false,"fork":false,"pushed_at":"2025-05-10T02:34:30.000Z","size":8069,"stargazers_count":932,"open_issues_count":81,"forks_count":168,"subscribers_count":52,"default_branch":"master","last_synced_at":"2025-05-10T03:38:12.945Z","etag":null,"topics":["backpressure","internet-of-things","iot","java","mqtt","mqtt-client","mqtt-protocol","mqtt5","reactive-programming","reactive-streams","reactor","rxjava"],"latest_commit_sha":null,"homepage":"https://hivemq.github.io/hivemq-mqtt-client/","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/hivemq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-02T21:15:55.000Z","updated_at":"2025-05-06T21:53:30.000Z","dependencies_parsed_at":"2023-11-19T16:28:03.130Z","dependency_job_id":"74febc1c-17e3-4335-9697-98efe03bd175","html_url":"https://github.com/hivemq/hivemq-mqtt-client","commit_stats":{"total_commits":1399,"total_committers":23,"mean_commits":60.82608695652174,"dds":0.1751250893495354,"last_synced_commit":"c747b708111485341c67a2239e733c35682fd58f"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hivemq%2Fhivemq-mqtt-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hivemq%2Fhivemq-mqtt-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hivemq%2Fhivemq-mqtt-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hivemq%2Fhivemq-mqtt-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hivemq","download_url":"https://codeload.github.com/hivemq/hivemq-mqtt-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101558,"owners_count":22014908,"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":["backpressure","internet-of-things","iot","java","mqtt","mqtt-client","mqtt-protocol","mqtt5","reactive-programming","reactive-streams","reactor","rxjava"],"created_at":"2024-07-31T18:01:01.425Z","updated_at":"2025-05-14T08:08:34.217Z","avatar_url":"https://github.com/hivemq.png","language":"Java","funding_links":[],"categories":["Clients","Java","进程间通信","Projects"],"sub_categories":["Java"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://www.hivemq.com/img/svg/hivemq-mqtt-client.svg\" width=\"500\" alt=\"HiveMQ MQTT Client\"\u003e\n\u003c/p\u003e\n\n# HiveMQ MQTT Client\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hivemq/hivemq-mqtt-client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hivemq/hivemq-mqtt-client)\n[![javadoc](https://javadoc.io/badge2/com.hivemq/hivemq-mqtt-client/javadoc.svg)](https://javadoc.io/doc/com.hivemq/hivemq-mqtt-client)\n[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/hivemq/hivemq-mqtt-client/.github/workflows/check.yml?branch=master)](https://img.shields.io/github/actions/workflow/status/hivemq/hivemq-mqtt-client/.github/workflows/check.yml?branch=master)\n\nMQTT 5.0 and 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and \nbackpressure support.\n\n- Documentation: https://hivemq.github.io/hivemq-mqtt-client/\n- Community forum: https://community.hivemq.com/\n- HiveMQ website: https://www.hivemq.com/\n- Contribution guidelines: [CONTRIBUTING.md](CONTRIBUTING.md)\n- License: [LICENSE](LICENSE)\n- MQTT resources:\n  - [MQTT Essentials](https://www.hivemq.com/mqtt-essentials/)\n  - [MQTT 5 Essentials](https://www.hivemq.com/mqtt-5/)\n\n## Features\n\n- **All [MQTT 3.1.1](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html) and \n  [MQTT 5.0](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html) features**\n- API flavors:\n  - **Reactive**: [Reactive Streams](https://www.reactive-streams.org/) compatible, \n    [RxJava](https://github.com/ReactiveX/RxJava) and [Reactor](https://github.com/reactor/reactor-core) APIs available\n  - **Asynchronous API**: futures and callbacks\n  - **Blocking API**: for quick start and testing\n  - Switch flexibly between flavours and use them concurrently\n  - Flavours are clearly separated but have a consistent API style\n- **Backpressure support**:\n  - QoS 1 and 2\n  - QoS 0 (dropping incoming messages, if necessary)\n  - Bringing MQTT flow control and reactive pull backpressure together\n- Transports:\n  - TCP\n  - **SSL/TLS**\n    - All TLS versions up to TLS 1.3 are supported\n    - TLS mutual authentication\n    - TLS Server Name Indication (SNI)\n    - TLS Session Resumption\n    - Default and customizable hostname verification\n  - **WebSocket**, Secure WebSocket\n  - **Proxy**: SOCKS4, SOCKS5, HTTP CONNECT\n  - All possible combinations\n- Automatic and configurable **thread management**\n- Automatic and configurable **reconnect handling and message redelivery**\n- Automatic and configurable **resubscribe if the session expired**\n- **Manual message acknowledgment**\n  - Selectively enable manual acknowledgment for specific streams\n  - Acknowledge messages that are emitted to multiple streams independently per stream\n    (the client aggregates the acknowledgments before sending MQTT acknowledgments)\n  - Order of manual acknowledgment does not matter\n    (the client automatically ensures the order of MQTT acknowledgments for 100% compatibility with the MQTT specification)\n- Lifecycle listeners\n  - When connected\n  - When disconnected or connection failed\n- MQTT 5 specific:\n  - Pluggable Enhanced Authentication support (additional to MQTT specification: server-triggered re-authentication)\n  - Automatic Topic Alias mapping\n  - Interceptors for QoS flows\n\n## Users\n\n[\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/BMW.svg/300px-BMW.svg.png\" alt=\"BMW CarIT\" height=\"60px\"/\u003e\n](https://github.com/bmwcarit) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://github.com/bmwcarit/joynr/raw/master/graphics/joynr-logo.png\" alt=\"joynr\" height=\"60px\"/\u003e\n](https://github.com/bmwcarit/joynr) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://www.openhab.org/openhab-logo.png\" alt=\"openHAB\" height=\"60px\"/\u003e\n](https://www.openhab.org/) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://eclipse.org/ditto/images/ditto.svg\" alt=\"Eclipse Ditto\" height=\"60px\"/\u003e\n](https://github.com/eclipse/ditto) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://avatars3.githubusercontent.com/u/11352045?s=200\u0026v=4\" alt=\"Open Smart Grid Platform\" height=\"60px\"/\u003e\n](https://github.com/OSGP/open-smart-grid-platform) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://raw.githubusercontent.com/EXXETA/correomqtt/develop/icon/ico/Icon_128x128.png\" alt=\"CorreoMQTT\" height=\"60px\"/\u003e\n](https://github.com/EXXETA/correomqtt) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://avatars.githubusercontent.com/u/32634858?s=200\u0026v=4\" alt=\"HiveMQ Spring Boot Starter\" height=\"60px\"/\u003e\n](https://github.com/SmartsquareGmbH/mqtt-starter) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://avatars.githubusercontent.com/u/16953511?s=200\u0026v=4\" alt=\"HiveMQ Spring Boot Starter\" height=\"60px\"/\u003e\n](https://www.openmuc.org/) \u0026nbsp;\u0026nbsp; [\n\u003cimg src=\"https://avatars.githubusercontent.com/u/20456341?s=200\u0026v=4\" alt=\"HiveMQ Spring Boot Starter\" height=\"60px\"/\u003e\n](https://github.com/leftshiftone/gaia-sdk)\n\nIf you use the HiveMQ MQTT Client in a project that is not listed here, feel free to open an issue or pull request.\n\n## How to use\n\nJava 8 or higher is required.\n\n### Dependency\n\n#### Gradle\n\nIf you use Gradle, just include the following inside your `build.gradle(.kts)` file.\n\n```groovy\ndependencies {\n  implementation(\"com.hivemq:hivemq-mqtt-client:1.3.5\")\n}\n```\n\nFor optional features you can choose to include additional modules:\n\n```groovy\ndependencies {\n  implementation(platform(\"com.hivemq:hivemq-mqtt-client-websocket:1.3.5\"))\n  implementation(platform(\"com.hivemq:hivemq-mqtt-client-proxy:1.3.5\"))\n  implementation(platform(\"com.hivemq:hivemq-mqtt-client-epoll:1.3.5\"))\n  implementation(\"com.hivemq:hivemq-mqtt-client-reactor:1.3.5\")\n}\n```\n\n#### Maven\n\nIf you use Maven, just include the following inside your `pom.xml` file.\n\n```xml\n\u003cproject\u003e\n    ...\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    ...\n\u003c/project\u003e\n```\n\nNOTE: You have to set the compiler version to `1.8` or higher.\n\n```xml\n\u003cproject\u003e\n    ...\n    \u003cproperties\u003e\n        \u003cmaven.compiler.source\u003e1.8\u003c/maven.compiler.source\u003e\n        \u003cmaven.compiler.target\u003e1.8\u003c/maven.compiler.target\u003e\n    \u003c/properties\u003e\n    ...\n\u003c/project\u003e\n```\n\nFor optional features you can choose to include additional modules:\n\n```xml\n\u003cproject\u003e\n    ...\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-websocket\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-proxy\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-epoll\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-reactor\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    ...\n\u003c/project\u003e\n```\n\n### Shaded version\n\nIf you are experiencing problems with transitive dependencies, you can try the shaded version.\nThis version packs the transitive dependencies which are only used internal under a different package name.\nThe shaded version includes the websocket, proxy and epoll modules.\nTo use the shaded version just append `-shaded` to the artifact name.\n\n#### Gradle\n\n```groovy\ndependencies {\n  implementation(\"com.hivemq:hivemq-mqtt-client-shaded:1.3.5\")\n}\n```\n\n#### Maven\n\n```xml\n\u003cproject\u003e\n    ...\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hivemq\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-shaded\u003c/artifactId\u003e\n            \u003cversion\u003e1.3.5\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    ...\n\u003c/project\u003e\n```\n\n### Snapshots\n\nSnapshots can be obtained using [JitPack](https://jitpack.io/#hivemq/hivemq-mqtt-client).\n\n#### Gradle\n\n```groovy\nrepositories {\n  ...\n  maven { url 'https://jitpack.io' }\n}\n\ndependencies {\n  implementation(\"com.github.hivemq.hivemq-mqtt-client:hivemq-mqtt-client:develop-SNAPSHOT\")\n\n  // snapshots for optional modules\n  implementation(platform(\"com.github.hivemq.hivemq-mqtt-client:hivemq-mqtt-client-websocket:develop-SNAPSHOT\"))\n  implementation(platform(\"com.github.hivemq.hivemq-mqtt-client:hivemq-mqtt-client-proxy:develop-SNAPSHOT\"))\n  implementation(platform(\"com.github.hivemq.hivemq-mqtt-client:hivemq-mqtt-client-epoll:develop-SNAPSHOT\"))\n  implementation(\"com.github.hivemq.hivemq-mqtt-client:hivemq-mqtt-client-reactor:develop-SNAPSHOT\")\n}\n```\n\n#### Maven\n\n```xml\n\u003cproject\u003e\n    ...\n    \u003crepositories\u003e\n        \u003crepository\u003e\n            \u003cid\u003ejitpack.io\u003c/id\u003e\n            \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n        \u003c/repository\u003e\n    \u003c/repositories\u003e\n    \n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.hivemq.hivemq-mqtt-client\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client\u003c/artifactId\u003e\n            \u003cversion\u003edevelop-SNAPSHOT\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n    \u003c!-- snapshots for optional modules --\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.hivemq.hivemq-mqtt-client\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-websocket\u003c/artifactId\u003e\n            \u003cversion\u003edevelop-SNAPSHOT\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.hivemq.hivemq-mqtt-client\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-proxy\u003c/artifactId\u003e\n            \u003cversion\u003edevelop-SNAPSHOT\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.hivemq.hivemq-mqtt-client\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-epoll\u003c/artifactId\u003e\n            \u003cversion\u003edevelop-SNAPSHOT\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.hivemq.hivemq-mqtt-client\u003c/groupId\u003e\n            \u003cartifactId\u003ehivemq-mqtt-client-reactor\u003c/artifactId\u003e\n            \u003cversion\u003edevelop-SNAPSHOT\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    ...\n\u003c/project\u003e\n```\n\nChange the artifact name to `hivemq-mqtt-client-shaded` to get snapshots of the shaded version.\n\nJitPack works for all branches and also specific commits.\nJust specify `\u003cbranch\u003e-SNAPSHOT` or the first 10 digits of the commit id in the version.\n\n## General principles\n\n- API and implementation are clearly separated. All classes inside `internal` packages must not be used directly.\n- The API is mostly fluent and uses fluent builders to create clients, configurations and messages.\n- The API is designed to be consistent:\n  - The same principles are used throughout the library.\n  - The MQTT 3 and 5 interfaces are as consistent as possible with only version-specific differences.\n\n## Creation of clients\n\nBase classes: `Mqtt3Client`, `Mqtt5Client`\n\n```java\nMqtt5Client client = MqttClient.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .useMqttVersion5()\n        .build();\nMqtt3Client client = MqttClient.builder()...useMqttVersion3().build();\n```\nOr if the version is known upfront:\n```java\nMqtt5Client client = Mqtt5Client.builder()...build();\nMqtt3Client client = Mqtt3Client.builder()...build();\n```\n\nFor each API style exists a specific `build...()` method.\n\n## API flavours\n\nEach API style has its own interface to separate them clearly.\nAt any time it is possible to switch the API style.\n\n### Blocking API\n\n - Builder method: `buildBlocking()`\n - Switch method: `client.toBlocking()`\n\n#### Examples\n\n##### Subscribe example\n\n```java\nfinal Mqtt5BlockingClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildBlocking();\n\nclient.connect();\n\ntry (final Mqtt5Publishes publishes = client.publishes(MqttGlobalPublishFilter.ALL)) {\n\n    client.subscribeWith().topicFilter(\"test/topic\").qos(MqttQos.AT_LEAST_ONCE).send();\n\n    publishes.receive(1, TimeUnit.SECONDS).ifPresent(System.out::println);\n    publishes.receive(100, TimeUnit.MILLISECONDS).ifPresent(System.out::println);\n\n} finally {\n    client.disconnect();\n}\n```\n\n##### Publish example\n\n```java\nMqtt5BlockingClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildBlocking();\n\nclient.connect();\nclient.publishWith().topic(\"test/topic\").qos(MqttQos.AT_LEAST_ONCE).payload(\"1\".getBytes()).send();\nclient.disconnect();\n```\n\n#### Connect\n\n```java\nclient.connect();\n```\nOr with customized properties of the Connect message:\n```java\nclient.connectWith().keepAlive(10).send();\n```\nOr with pre-built Connect message:\n```java\nMqtt5Connect connectMessage = Mqtt5Connect.builder().keepAlive(10).build();\nclient.connect(connectMessage);\n```\n\n#### Publish\n\n```java\nclient.publishWith()\n        .topic(\"test/topic\")\n        .qos(MqttQos.AT_LEAST_ONCE)\n        .payload(\"payload\".getBytes())\n        .send();\n```\nOr with pre-built Publish message:\n```java\nMqtt5Publish publishMessage = Mqtt5Publish.builder()\n        .topic(\"test/topic\")\n        .qos(MqttQos.AT_LEAST_ONCE)\n        .payload(\"payload\".getBytes())\n        .build();\nclient.publish(publishMessage);\n```\n\n#### Subscribe\n\n```java\nclient.subscribeWith().topicFilter(\"test/topic\").qos(MqttQos.EXACTLY_ONCE).send();\n```\nOr with pre-built Subscribe message:\n```java\nMqtt5Subscribe subscribeMessage = Mqtt5Subscribe.builder()\n        .topicFilter(\"test/topic\")\n        .qos(MqttQos.EXACTLY_ONCE)\n        .build();\nclient.subscribe(subscribeMessage);\n```\n\n#### Unsubscribe\n\n```java\nclient.unsubscribeWith().topicFilter(\"test/topic\").send();\n```\nOr with pre-built Unsubscribe message:\n```java\nMqtt5Unsubscribe unsubscribeMessage = Mqtt5Unsubscribe.builder().topicFilter(\"test/topic\").build();\nclient.unsubscribe(unsubscribeMessage);\n```\n\n#### Consume messages\n\n```java\ntry (Mqtt5BlockingClient.Mqtt5Publishes publishes = client.publishes(MqttGlobalPublishFilter.ALL)) {\n    Mqtt5Publish publishMessage = publishes.receive();\n    // or with timeout\n    Optional\u003cMqtt5Publish\u003e publishMessage = publishes.receive(10, TimeUnit.SECONDS);\n    // or without blocking\n    Optional\u003cMqtt5Publish\u003e publishMessage = publishes.receiveNow();\n}\n```\n\n`publishes` must be called before `subscribe` to ensure no message is lost.\nIt can be called before `connect` to receive messages of a previous session.\n\n#### Disconnect\n\n```java\nclient.disconnect();\n```\nOr with customized properties of the DISCONNECT message (only MQTT 5):\n```java\nclient.disconnectWith().reasonString(\"test\").send();\n```\nOr with pre-built Disconnect message (only MQTT 5):\n```java\nMqtt5Disconnect disconnectMessage = Mqtt5Disconnect.builder().reasonString(\"test\").build();\nclient.disconnect(disconnectMessage);\n```\n\n#### Reauth (only MQTT 5)\n\n```java\nclient.reauth();\n```\n\n### Async API\n\n - Builder method: `buildAsync()`\n - Switch method: `client.toAsync()`\n\n#### Examples\n\n##### Subscribe example\n\n```java\nMqtt5BlockingClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildBlocking();\n\nclient.connect();\n\nclient.toAsync().subscribeWith()\n        .topicFilter(\"test/topic\")\n        .qos(MqttQos.AT_LEAST_ONCE)\n        .callback(System.out::println)\n        .send();\n```\n\n##### Publish example\n\n```java\nMqtt5AsyncClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildAsync();\n\nclient.connect()\n        .thenCompose(connAck -\u003e client.publishWith().topic(\"test/topic\").payload(\"1\".getBytes()).send())\n        .thenCompose(publishResult -\u003e client.disconnect());\n```\n\n#### Connect\n\n`connect()`, `connectWith()` and `connect(Mqtt3/5Connect)` method calls are analog to the Blocking API but return\n`CompletableFuture`.\n\n#### Publish\n\n`publishWith()` and `publish(Mqtt3/5Publish)` method calls are analog to the Blocking API but return\n`CompletableFuture`.\n\n#### Subscribe\n\n`subscribeWith()` and `subscribe(Mqtt3/5Subscribe)` method calls are analog to the Blocking API but return\n`CompletableFuture`.\n\nAdditionally messages can be consumed per subscribe:\n```java\nclient.subscribeWith()\n        .topicFilter(\"test/topic\")\n        .qos(MqttQos.EXACTLY_ONCE)\n        .callback(System.out::println)\n        .executor(executor) // optional\n        .send();\n```\nOr with pre-built Subscribe message:\n```java\nMqtt5Subscribe subscribeMessage = Mqtt5Subscribe.builder()\n        .topicFilter(\"test/topic\")\n        .qos(MqttQos.EXACTLY_ONCE)\n        .build();\nclient.subscribe(subscribeMessage, System.out::println);\nclient.subscribe(subscribeMessage, System.out::println, executor);\n```\n\n#### Unsubscribe\n\n`unsubscribeWith()` and `unsubscribe(Mqtt3/5Unsubscribe)` method calls are analog to the Blocking API but return\n`CompletableFuture`.\n\n#### Consume messages\n\nMessages can either be consumed per subscribe (described above) or globally:\n\n```java\nclient.publishes(MqttGlobalPublishFilter.ALL, System.out::println);\n```\nOr with executing the callback on a specified executor:\n```java\nclient.publishes(MqttGlobalPublishFilter.ALL, System.out::println, executor);\n```\n\n`publishes` must be called before `subscribe` to ensure no message is lost.\nIt can be called before `connect` to receive messages of a previous session.\n\n#### Disconnect\n\n`disconnect()`, `disconnectWith()` and `disconnect(Mqtt5Disconnect)` method calls are analog to the Blocking API but\nreturn `CompletableFuture`.\n\n#### Reauth (only MQTT 5)\n\n`reauth()` method call is analog to the Blocking API but returns `CompletableFuture`.\n\n### Reactive API\n\n - Builder method: `buildRx()`\n - Switch method: `client.toRx()`\n\n#### Examples\n\n##### Subscribe example\n\n```java\nMqtt5RxClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildRx();\n\n// As we use the reactive API, the following line does not connect yet, but returns a reactive type.\n// e.g. Single is something like a lazy and reusable future. Think of it as a source for the ConnAck message.\nSingle\u003cMqtt5ConnAck\u003e connAckSingle = client.connect();\n\n// Same here: the following line does not subscribe yet, but returns a reactive type.\n// FlowableWithSingle is a combination of the single SubAck message and a Flowable of Publish messages.\n// A Flowable is an asynchronous stream that enables backpressure from the application over the client to the broker.\nFlowableWithSingle\u003cMqtt5Publish, Mqtt5SubAck\u003e subAckAndMatchingPublishes = client.subscribeStreamWith()\n        .topicFilter(\"a/b/c\").qos(MqttQos.AT_LEAST_ONCE)\n        .addSubscription().topicFilter(\"a/b/c/d\").qos(MqttQos.EXACTLY_ONCE).applySubscription()\n        .applySubscribe();\n\n// The reactive types offer many operators that will not be covered here.\n// Here we register callbacks to print messages when we received the CONNACK, SUBACK and matching PUBLISH messages.\nCompletable connectScenario = connAckSingle\n        .doOnSuccess(connAck -\u003e System.out.println(\"Connected, \" + connAck.getReasonCode()))\n        .doOnError(throwable -\u003e System.out.println(\"Connection failed, \" + throwable.getMessage()))\n        .ignoreElement();\n\nCompletable subscribeScenario = subAckAndMatchingPublishes\n        .doOnSingle(subAck -\u003e System.out.println(\"Subscribed, \" + subAck.getReasonCodes()))\n        .doOnNext(publish -\u003e System.out.println(\n                \"Received publish\" + \", topic: \" + publish.getTopic() + \", QoS: \" + publish.getQos() +\n                        \", payload: \" + new String(publish.getPayloadAsBytes())))\n        .ignoreElements();\n\n// Reactive types can be easily and flexibly combined\nconnectScenario.andThen(subscribeScenario).blockingAwait();\n```\n\n##### Publish example\n\n```java\nMqtt5RxClient client = Mqtt5Client.builder()\n        .identifier(UUID.randomUUID().toString())\n        .serverHost(\"broker.hivemq.com\")\n        .buildRx();\n\n// As we use the reactive API, the following line does not connect yet, but returns a reactive type.\nCompletable connectScenario = client.connect()\n        .doOnSuccess(connAck -\u003e System.out.println(\"Connected, \" + connAck.getReasonCode()))\n        .doOnError(throwable -\u003e System.out.println(\"Connection failed, \" + throwable.getMessage()))\n        .ignoreElement();\n\n// Fake a stream of Publish messages with an incrementing number in the payload\nFlowable\u003cMqtt5Publish\u003e messagesToPublish = Flowable.range(0, 10_000)\n        .map(i -\u003e Mqtt5Publish.builder()\n                .topic(\"a/b/c\")\n                .qos(MqttQos.AT_LEAST_ONCE)\n                .payload((\"test \" + i).getBytes())\n                .build())\n        // Emit 1 message only every 100 milliseconds\n        .zipWith(Flowable.interval(100, TimeUnit.MILLISECONDS), (publish, i) -\u003e publish);\n\n// As we use the reactive API, the following line does not publish yet, but returns a reactive type.\nCompletable publishScenario = client.publish(messagesToPublish)\n        .doOnNext(publishResult -\u003e System.out.println(\n                \"Publish acknowledged: \" + new String(publishResult.getPublish().getPayloadAsBytes())))\n        .ignoreElements();\n\n// As we use the reactive API, the following line does not disconnect yet, but returns a reactive type.\nCompletable disconnectScenario = client.disconnect().doOnComplete(() -\u003e System.out.println(\"Disconnected\"));\n\n// Reactive types can be easily and flexibly combined\nconnectScenario.andThen(publishScenario).andThen(disconnectScenario).blockingAwait();\n```\n\n#### Connect\n\n`connect()`, `connectWith()` and `connect(Mqtt3/5Connect)` method calls are analog to the Async and Blocking API but\nreturn `Single\u003cConnAck\u003e`.\n\n#### Publish\n\n`publish` takes a reactive stream of Publish messages (`Flowable`) and returns a reactive stream of Publish results\n(`Flowable`).\n\nThe Reactive API is usually not used for publishing single messages.\nNevertheless it is possible with the following code.\n\n```java\nSingle\u003cMqtt5PublishResult\u003e result =\n        client.publish(Flowable.just(Mqtt5Publish.builder()\n                .topic(\"test/topic\")\n                .qos(MqttQos.AT_LEAST_ONCE)\n                .payload(\"payload\".getBytes())\n                .build())).singleOrError();\n\n```\n\n#### Subscribe\n\n`subscribeWith()` and `subscribe(Mqtt3/5Subscribe)` method calls are analog to the Async and Blocking API but return\n`Single\u003cSubAck\u003e`.\n\nAdditionally messages can be consumed per subscribe:\n```java\nFlowable\u003cMqtt5Publish\u003e result =\n        client.subscribeStreamWith()\n                .topicFilter(\"test/topic\")\n                .qos(MqttQos.EXACTLY_ONCE)\n                .applySubscribe()\n                .doOnSingle(subAck -\u003e System.out.println(\"subscribed\"))\n                .doOnNext(publish -\u003e System.out.println(\"received publish\"));\n```\nOr with pre-built Subscribe message:\n```java\nMqtt5Subscribe subscribeMessage = Mqtt5Subscribe.builder()\n        .topicFilter(\"test/topic\")\n        .qos(MqttQos.EXACTLY_ONCE)\n        .build();\nFlowable\u003cMqtt5Publish\u003e result =\n        client.subscribeStreamWith(subscribeMessage)\n                .doOnSingle(subAck -\u003e System.out.println(\"subscribed\"))\n                .doOnNext(publish -\u003e System.out.println(\"received publish\"));\n```\n\n#### Unsubscribe\n\n`unsubscribeWith()` and `unsubscribe(Mqtt3/5Unsubscribe)` method calls are analog to the Async and Blocking API but\nreturn `Single\u003cUnsubAck\u003e`.\n\n#### Consume messages\n\nMessages can either be consumed per subscribe (described above) or globally:\n\n```java\nFlowable\u003cMqtt5Publish\u003e result =\n        client.publishes(MqttGlobalPublishFilter.ALL).doOnNext(System.out::println);\n```\n\n`publishes` must be called before `subscribe` to ensure no message is lost.\nIt can be called before `connect` to receive messages of a previous session.\n\n#### Disconnect\n\n`disconnect()`, `disconnectWith()` and `disconnect(Mqtt5Disconnect)` method calls are analog to the Async and Blocking\nAPI but return `Completable`.\n\n#### Reauth (only MQTT 5)\n\n`reauth()` method call is analog to the Async and Blocking API but returns `Completable`.\n\n## Versioning\n\n[Semantic Versioning](https://semver.org/) is used.\n\nAll code inside `com.hivemq.client.internal` packages must not be used directly. It can change at any time and is not\npart of the public API.\n\nInterfaces annotated with `DoNotImplement` must not be implemented. The implementation is provided by the library.\nThis allows the library to later add methods to the interface without breaking backwards compatibility with implementing\nclasses.\n\n## Contributing\n\nIf you want to contribute to HiveMQ MQTT Client, see the [contribution guidelines](CONTRIBUTING.md).\n\n## License\n\nHiveMQ MQTT Client is licensed under the `APACHE LICENSE, VERSION 2.0`. A copy of the license can be found [here](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhivemq%2Fhivemq-mqtt-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhivemq%2Fhivemq-mqtt-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhivemq%2Fhivemq-mqtt-client/lists"}