Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hivemq/hivemq-mqtt-spring-boot-starter
A Spring Boot Starter to integrate the awesome HiveMQ MQTT Client SDK into your Spring Boot application
https://github.com/hivemq/hivemq-mqtt-spring-boot-starter
Last synced: 5 days ago
JSON representation
A Spring Boot Starter to integrate the awesome HiveMQ MQTT Client SDK into your Spring Boot application
- Host: GitHub
- URL: https://github.com/hivemq/hivemq-mqtt-spring-boot-starter
- Owner: hivemq
- License: apache-2.0
- Created: 2024-02-13T14:46:58.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-22T21:55:48.000Z (7 months ago)
- Last Synced: 2024-04-22T22:59:12.866Z (7 months ago)
- Language: Java
- Homepage:
- Size: 131 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# HiveMQ MQTT Spring Boot Starter
[![CI Check](https://github.com/hivemq/hivemq-mqtt-spring-boot-starter/actions/workflows/check.yml/badge.svg)](https://github.com/hivemq/hivemq-mqtt-spring-boot-starter/actions/workflows/check.yml)
This Spring Boot Starter can be used to add and configure the [HiveMQ MQTT Client](https://github.com/hivemq/hivemq-mqtt-client) to your Spring project.
__IMPORTANT: This is still work in progress and not yet ready for production use!__
## How to use
### Add the dependency
The starter is not yet available on Maven Central. In order to use it in your project you would need to build and publish it locally: Building and publishing locally is straight forward. Just clone the repository and run the following command:
```shell
./gradlew publishToMavenLocal
````Check `gradle.properties` for the current version.
#### Gradle
```kotlin
// add local maven repository
repositories {
mavenLocal()
}// add the dependency
implementation("com.hivemq:hivemq-mqtt-spring-boot-starter:")```
#### Maven
```xml
local-maven-repo
file://${user.home}/.m2/repository
com.hivemq
hivemq-mqtt-spring-boot-starter
```
### Autowire the client
The HiveMQ MQTT Client supports 3 different [API flavors](https://hivemq.github.io/hivemq-mqtt-client/docs/api-flavours/):
- Blocking
- Async
- Reactive.It is possible to autowire the client for preferred API. Simple declare a dependency of the desired type in your Spring component.
#### Blocking Client
```java
@Service
public class MyService {private final Mqtt5BlockingClient mqttClient;
public MyService(final Mqtt5BlockingClient mqttClient) {
this.mqttClient = mqttClient;
}
}
```#### Async Client
```java
@Service
public class MyService {private final Mqtt5AsyncClient mqttClient;
public MyService(final Mqtt5AsyncClient mqttClient) {
this.mqttClient = mqttClient;
}
}
```#### Reactive Client
```java
@Service
public class MyService {private final Mqtt5RxClient mqttClient;
public MyService(final Mqtt5RxClient mqttClient) {
this.mqttClient = mqttClient;
}
}
```See the official [HiveMQ MQTT Client Documentation](https://hivemq.github.io/hivemq-mqtt-client/) for more details on how to use the client.
## Configuration
| Property | Description | Default |
|---------------------------|-------------|---------|
| `hivemq.client.server-uri` | The URI of the MQTT broker to connect to. | `tcp://localhost:1883` |
| `hivemq.client.client-id` | The client id to use for the connection. | `null` |
| `hivemq.client.mqtt-version` | The MQTT version to use. | `5` |
| `hivemq.client.connection-timeout` | The connection timeout in milliseconds. | `10000` |
| `hivemq.client.manual-acks` | Whether to use manual acks. | `false` |
| `hivemq.client.password` | The password to use for the connection. | `null` |
| `hivemq.client.username` | The username to use for the connection. | `null` |
| `hivemq.client.keep-alive-interval` | The keep alive interval in seconds. | `60` |
| `hivemq.client.max-reconnect-delay` | The maximum reconnect delay in milliseconds. | `30000` |
| `hivemq.client.automatic-reconnect` | Whether to automatically reconnect. | `false` |
| `hivemq.client.will-message.payload` | The payload of the will message. | `null` |
| `hivemq.client.will-message.qos` | The QoS of the will message. | `0` |
| `hivemq.client.will-message.topic` | The topic of the will message. | `null` |
| `hivemq.client.will-message.retained` | Whether the will message should be retained. | `false` |
| `hivemq.client.ssl-properties.certificate` | The path to the client certificate. | `null` |
| `hivemq.client.ssl-properties.private-key` | The path to the client private key. | `null` |
| `hivemq.client.ssl-properties.certificate-authority` | The path to the certificate authority. | `null` |
| `hivemq.client.ssl-properties.password` | The password for the client certificate. | `null` |
| `hivemq.client.clean-session` | Whether to use a clean session. | `false` |
| `hivemq.client.clean-start` | Whether to use a clean start. | `false` |
| `hivemq.client.session-expiry-interval` | The session expiry interval in seconds. | `10000` |
| `hivemq.client.receive-maximum` | The maximum number of incoming messages. | `100` |
| `hivemq.client.maximum-packet-size` | The maximum packet size. | `10000` |
| `hivemq.client.topic-alias-maximum` | The maximum number of topic aliases. | `10` |
| `hivemq.client.request-problem-info` | Whether to request problem info. | `false` |
| `hivemq.client.request-response-info` | Whether to request response info. | `false` |
| `hivemq.client.user-properties.key1` | The key of the first user property. | `null` |```properties
hivemq.client.server-uri=tcp://localhost:1883
hivemq.client.client-id=client1
hivemq.client.mqtt-version=5
hivemq.client.connection-timeout=10000
hivemq.client.manual-acks=false
hivemq.client.password=123
hivemq.client.username=user
hivemq.client.keep-alive-interval=60
hivemq.client.max-reconnect-delay=30000
hivemq.client.automatic-reconnect=false
hivemq.client.will-message.payload=offline
hivemq.client.will-message.qos=1
hivemq.client.will-message.topic=will
hivemq.client.will-message.retained=false
hivemq.client.ssl-properties.certificate=/client.crt
hivemq.client.ssl-properties.private-key=/client.key
hivemq.client.ssl-properties.certificate-authority=/ca.crt
hivemq.client.ssl-properties.password=123
hivemq.client.clean-session=false
hivemq.client.clean-start=false
hivemq.client.session-expiry-interval=10000
hivemq.client.receive-maximum=100
hivemq.client.maximum-packet-size=10000
hivemq.client.topic-alias-maximum=10
hivemq.client.request-problem-info=false
hivemq.client.request-response-info=false
hivemq.client.user-properties.key1=value1
```