You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-operations/create-edge-apps/concept-about-state-store-protocol.md
+9-8Lines changed: 9 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,16 +8,17 @@ ms.topic: concept-article
8
8
ms.date: 10/30/2024
9
9
10
10
# CustomerIntent: As a developer, I want understand what the MQTT broker state store protocol is, so
11
-
# that I can implement a client app to interact with the MQ state store.
11
+
# that I can implement a client app to interact with the state store.
12
12
ms.service: azure-iot-operations
13
13
---
14
14
15
-
# MQTT broker state store protocol
15
+
# State store protocol
16
16
17
-
The MQ state store is a distributed storage system within the Azure IoT Operations cluster. The state store offers the same high availability guarantees as MQTT messages in MQTT broker. According to the MQTT5/RPC protocol guidelines, clients should use MQTT5 to interact with the MQ state store. This article provides protocol guidance for developers who need to implement their own MQTT broker state store clients.
17
+
The state store is a distributed storage system within the Azure IoT Operations cluster. The state store offers the same high availability guarantees as MQTT messages in MQTT broker. According to the MQTT5/RPC protocol guidelines, clients should use MQTT5 to interact with the state store. This article provides protocol guidance for developers who need to implement their own state store clients.
18
18
19
-
## State store protocol overview
20
-
The MQ state store supports the following commands:
19
+
## Overview
20
+
21
+
The state store supports the following commands:
21
22
22
23
-`SET`\<keyName\>\<keyValue\>\<setOptions\>
23
24
-`GET`\<keyName\>
@@ -71,7 +72,7 @@ sequenceDiagram
71
72
72
73
The commands `SET`, `GET`, and `DEL` behave as expected.
73
74
74
-
The values that the `SET` command sets, and the `GET` command retrieves, are arbitrary binary data. The size of the values is only limited by the maximum MQTT payload size, and resource limitations of MQ and the client.
75
+
The values that the `SET` command sets, and the `GET` command retrieves, are arbitrary binary data. The size of the values is only limited by the maximum MQTT payload size, and resource limitations of MQTT broker and the client.
75
76
76
77
### `SET` options
77
78
@@ -120,7 +121,7 @@ The following example output shows state store RESP3 payloads:
120
121
```
121
122
122
123
> [!NOTE]
123
-
> Note that `SET` requires additional MQTT5 properties, as explained in the section [Versioning and hybrid logical clocks](#versioning-and-hybrid-logical-clocks).
124
+
> `SET` requires additional MQTT5 properties, as explained in the section [Versioning and hybrid logical clocks](#versioning-and-hybrid-logical-clocks).
124
125
125
126
### Response format
126
127
@@ -421,7 +422,7 @@ The topic is defined in the following example. The `clientId` is an upper-case h
Copy file name to clipboardExpand all lines: articles/iot-operations/create-edge-apps/edge-apps-overview.md
+13-23Lines changed: 13 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The following sections explain the settings and features that contribute to a ro
21
21
22
22
## Quality of service (QoS)
23
23
24
-
Both publishers and subscribers should use [QoS-1](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901236) to guarantee message delivery at least once. The broker stores and retransmits messages until it receives an acknowledgment (ACK) from the recipient, ensuring no messages are lost during transmission.
24
+
Both publishers and subscribers should use [QoS-1](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901236) to guarantee message delivery at least once. The MQTT broker stores and retransmits messages until it receives an acknowledgment (ACK) from the recipient, ensuring no messages are lost during transmission.
25
25
26
26
## Session type and Clean-Session flag
27
27
@@ -55,13 +55,13 @@ MQTT subscriptions with QoS-1 ensure eventual consistency across identical appli
55
55
56
56
[Shared subscriptions](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901250) enable load balancing across multiple instances of a highly available application. Instead of each subscriber receiving a copy of every message, the messages are distributed evenly among the subscribers. MQTT broker currently only supports a round robin algorithm to distribute messages allowing an application to scale out. A typical use case is to deploy multiple pods using Kubernetes ReplicaSet that all subscribe to MQTT broker using the same topic filter in shared subscription.
57
57
58
-
## Use MQTT broker's built-in key-value store (distributed HashMap)
58
+
## State store
59
59
60
-
MQTT broker's built-in key-value store is a simple, replicated in-memory *HashMap* for managing application processing state. Unlike *etcd*, for example, MQTT broker prioritizes high-velocity throughput, horizontal scaling, and low latency through in-memory data structures, partitioning, and chain-replication. It allows applications to use the broker's distributed nature and fault tolerance while accessing a consistent state quickly across instances. To use the built-in key-value store provided by the distributed broker:
60
+
State store is a replicated in-memory *HashMap* for managing application processing state. Unlike *etcd*, for example, state store prioritizes high-velocity throughput, horizontal scaling, and low latency through in-memory data structures, partitioning, and chain-replication. It allows applications to use the state stores distributed nature and fault tolerance while accessing a consistent state quickly across instances. To use the built-in key-value store provided by the distributed broker:
61
61
62
62
* Implement ephemeral storage and retrieval operations using the broker's key-value store API, ensuring proper error handling and data consistency. Ephemeral state is a short-lived data storage used in stateful processing for fast access to intermediate results or metadata during real-time computations. In the context of HA application, an ephemeral state helps recover application states between crashes. It can be written to disk but remains temporary, as opposed to cold storage that's designed for long-term storage of infrequently accessed data.
63
63
64
-
* Use the key-value store for sharing state, caching, configuration, or other essential data among multiple instances of the application, allowing them to keep a consistent view of the data.
64
+
* Use the state store for sharing state, caching, configuration, or other essential data among multiple instances of the application, allowing them to keep a consistent view of the data.
65
65
66
66
## Use MQTT broker's built-in Dapr integration
67
67
@@ -75,25 +75,15 @@ For simpler use cases an application might utilize [Dapr](https://dapr.io) (Dist
75
75
76
76
## Checklist to develop a highly available application
77
77
78
-
- Choose an appropriate MQTT client library for your programming language. The client should support MQTT v5. Use a C or Rust based library if your application is sensitive to latency.
79
-
- Configure the client library to connect to MQTT broker with *clean-session* flag set to false and the desired QoS level (QoS-1).
80
-
- Decide a suitable value for session expiry, message expiry, and keep-alive intervals.
81
-
- Implement the message processing logic for the subscriber application, including sending an acknowledgment when the message has been successfully delivered or processed.
82
-
- For multithreaded applications, configure the *max-receive* parameter to enable parallel message processing.
83
-
- Utilize retained messages for keeping temporary application state.
84
-
- Utilize MQTT broker's built-in key-value store to manage ephemeral application state.
85
-
- Evaluate Dapr to develop your application if your use case is simple and doesn't require detailed control over the MQTT connection or message handling.
86
-
- Implement shared subscriptions to distribute messages evenly among multiple instances of the application, allowing for efficient scaling.
87
-
88
-
## Example
89
-
90
-
The following example implements contextualization and normalization of data with a highly available northbound connector
91
-
92
-
A northbound application consists of input and output stages, and an optional processing stage. The input stage subscribes to a distributed MQTT broker to receive data, while the output stage ingests messages into a cloud data-lake. The processing stage executes contextualization and normalization logic on the received data.
93
-
94
-

95
-
96
-
To ensure high availability, the input stage connects to MQTT broker and sets the *clean-session* flag to false for persistent sessions, using QoS-1 for reliable message delivery, acknowledging messages post-processing by the output stage. Additionally, the application might use the built-in *HashMap* key-value store for temporary state management and the round robin algorithm to load-balance multiple instances using shared subscriptions.
78
+
* Choose an appropriate MQTT client library for your programming language. The client should support MQTT v5. Use a C or Rust based library if your application is sensitive to latency.
79
+
* Configure the client library to connect to MQTT broker with *clean-session* flag set to `false` and the desired QoS level (QoS-1).
80
+
* Decide a suitable value for session expiry, message expiry, and keep-alive intervals.
81
+
* Implement the message processing logic for the subscriber application, including sending an acknowledgment when the message has been successfully delivered or processed.
82
+
* For multithreaded applications, configure the *max-receive* parameter to enable parallel message processing.
83
+
* Utilize retained messages for keeping temporary application state.
84
+
* Utilize the distributed state store to manage ephemeral application state.
85
+
* Evaluate Dapr to develop your application if your use case is simple and doesn't require detailed control over the MQTT connection or message handling.
86
+
* Implement shared subscriptions to distribute messages evenly among multiple instances of the application, allowing for efficient scaling.
title: Persisting data in the MQTT broker state store
3
+
description: Understand how to develop application that persist data between sessions using the state store.
4
+
author: PatAltimore
5
+
ms.subservice: azure-mqtt-broker
6
+
ms.author: patricka
7
+
ms.topic: concept-article
8
+
ms.custom:
9
+
- ignite-2023
10
+
ms.date: 11/12/2024
11
+
12
+
#CustomerIntent: As an developer, I want understand how to develop application that persist data between sessions using the state store.
13
+
ms.service: azure-iot-operations
14
+
---
15
+
16
+
# Persisting data in the state store
17
+
18
+
The state store is a distributed storage system, deployed as part of Azure IoT Operations. Using the state store, applications can get, set, and delete key-value pairs, without needing to install more services, such as Redis. The state store also provides versioning of the data, and also the primitives for building distributed locks, ideal for highly available applications.
19
+
20
+
Like Redis, the state store uses in memory storage. Stopping or restarting the Kubernetes cluster causes the state store contents to be lost.
21
+
22
+
The state store is implemented via MQTTv5. Its service is integrated directly into MQTT broker and is automatically started when the broker starts. The state store provides the same high availability as the MQTT broker.
23
+
24
+
## Why use the state store?
25
+
26
+
The state store allows an edge application to persist data on the edge. Typical uses of the state store include:
27
+
28
+
* Creating stateless applications
29
+
* Sharing state between applications
30
+
* Developing highly available applications
31
+
* Storing data to be used by dataflows
32
+
33
+
## State store authorization
34
+
35
+
The state store extends MQTT broker's authorization mechanism, allowing individual clients to have optional read and write access to specific keys. Read more on how to [configure MQTT broker authorization](../manage-mqtt-broker/howto-configure-authorization.md) for the state store.
36
+
37
+
## Interacting with the state store
38
+
39
+
A CLI tool is available which enables interaction with the state store from a shell running on any machine.
40
+
41
+
1. Generate an X.509 certificate chain for authenticating with MQTT broker
42
+
1. Create a `BrokerAuthentication` using x.509 certificates
43
+
1. Create a `BrokerListener` of type LoadBalancer which enables off-cluster access
44
+
1. Open ports on your cluster to enable access to the MQTT broker.
45
+
46
+
For instructions on setting up your cluster and using the tool, refer to the [state store CLI GitHub](https://github.com/Azure-Samples/explore-iot-operations/tree/main/tools/state-store-cli) page.
47
+
48
+
> [!NOTE]
49
+
> SDKs to interact with the state store are currently in active development, and will be available in the near future to enable edge applications to interact with the state store.
50
+
51
+
## Related content
52
+
53
+
*[Learn about the MQTT broker state store protocol](concept-about-state-store-protocol.md)
0 commit comments