Configuring administrative subscriptions
Use administrative subscriptions to ensure that a subscription continues to exist and receive messages when there are no clients that are using the subscription.
You might want to use administrative subscriptions (admin subscriptions) to allow ephemeral clients to share a subscription that is not removed, along with any buffered messages, in the event of all clients being disconnected due to a network outage. Examples of ephemeral clients might include MQTT v3.1.1 clients with a clean session flag set to true, or MQTT v5 clients with a session expiry interval set to 0.
When multiple MQTT clients are connected to a shared subscription, and one client disconnects after receiving messages but before sending an acknowledgment, it can be useful to have those messages sent to another client rather than waiting for the original client to reconnect and complete transmission of the acknowledgment. Resending the messages to another client prevents the messages waiting for the original client to reconnect but does create duplicate messages, as the message is sent to two clients that might both process the message.
- AdminSubscription
- Used by shared subscriptions in the __SharedM namespace
- DurableNamespaceAdminSub
- Used by shared subscriptions in the __Shared namespace
- NonpersistentAdminSub
- Used by shared subscriptions in the __SharedND namespace
For all three types of subscription, the name of the configuration object must match the subscription name. For admin subscriptions, the name must include the topic filter and a leading forward slash character '/' . For the other subscriptions, the name must not contain slashes, and the topic filter must form part of the definition. This naming convention makes it possible to link the results that come from Subscription monitor with the configuration objects.
The following example shows the format of the payload that is required to create an admin subscription:
"AdminSubscription": {
"/{ShareName}/{TopicFilter}": {
"SubscriptionPolicy": "{PolicyName}",
"MaxQualityOfService": {MaxQualityOfService},
"AddRetainedMsgs": {AddRetainedMsgs},
"QualityOfServiceFilter": "{QualityOfServiceFilter}"
}
}
{ShareName}
and{TopicFilter}
are taken from the topic on which a shared subscriber subscribes.$share/{ShareName}/{TopicFilter}){PolicyName}
is the SubscriptionPolicy that this subscription uses for properties.-
{MaxQualityOfService}
is the maximum QoS that associated with the created subscription. Valid values are 0,1, or 2. The default value is 0. {AddRetainedMsgs}
specifies whether, when the subscription is created, it should be populated with matching retained messages. Valid values are True or False. The default value is True.{QualityOfServiceFilter}
specifies whether a quality of service filter is applied to published messages before the messages are added to the subscription. Valid values are:- None. no filtering applied (all messages are added to the subscription)
- QoS=0. meaning that only messages published at QoS 0 are added to the subscription
- QoS>0. meaning that only messages published at QoS greater than 0 (so, 1 or 2) are added to the subscription .these are the only available filter options. default: None.
The following example shows the format of the payload that is required to create a global-shared durable admin subscription:
"DurableNamespaceAdminSub": {
"{SubName}": {
"SubscriptionPolicy": "{PolicyName}",
"TopicFilter": "{TopicFilter}",
"MaxQualityOfService": {MaxQualityOfService},
"AddRetainedMsgs": {AddRetainedMsgs},
"QualityOfServiceFilter": "{QualityOfServiceFilter}"
}
}
{SubName}
and{TopicFilter}
are taken from the topic on which a shared subscriber subscribes.$SharedSubscription/{SubName}/{TopicFilter}){PolicyName}
is the SubscriptionPolicy that this subscription uses for properties.-
{MaxQualityOfService}
is the maximum QoS that associated with the created subscription. Valid values are 0,1, or 2. The default value is 0. {AddRetainedMsgs}
specifies whether, when the subscription is created, it should be populated with matching retained messages. Valid values are True or False. The default value is True.{QualityOfServiceFilter}
specifies whether a quality of service filter is applied to published messages before the messages are added to the subscription. Valid values are:- None. no filtering applied (all messages are added to the subscription)
- QoS=0. meaning that only messages published at QoS 0 are added to the subscription
- QoS>0. meaning that only messages published at QoS greater than 0 (so, 1 or 2) are added to the subscription .these are the only available filter options. default: None.
The following example shows the format of the payload that is required to create a global-shared non-durable admin subscription:
"NonpersistentAdminSub": {
"{SubName}": {
"TopicPolicy": "{PolicyName}",
"TopicFilter": "{TopicFilter}",
"MaxQualityOfService": {MaxQualityOfService},
"AddRetainedMsgs": {AddRetainedMsgs},
"QualityOfServiceFilter": "{QualityOfServiceFilter}"
}
}
{SubName}
and{TopicFilter}
are taken from the topic on which a shared subscriber subscribes.$SharedSubscription/{SubName}/{TopicFilter}){PolicyName}
is the TopicPolicy that this subscription uses for its properties.-
{MaxQualityOfService}
is the maximum QoS that is associated with the subscription. Valid values are 0,1, or 2. The default value is 0. {AddRetainedMsgs}
specifies whether, when the subscription is created, it is populated with matching retained messages. Valid values are True or False. The default value is True.{QualityOfServiceFilter}
specifies whether a quality of service filter is applied to published messages before the messages are added to the subscription. Valid values are:- None. No filtering is applied so all messages are added to the subscription. This value is the default value.
- QoS=0. Only messages that are published at QoS 0 are added to the subscription.
- QoS>0. Only messages that are published at QoS greater than 0 are added to the subscription.
These types of subscription are not created by a connected client application, and therefore do not come through an endpoint. The policies that are used to provide the subscription properties do not have to appear on an endpoint either, so you can define these types of subscription with specific policies that are not used for authorization, and that use other policies on the endpoint to allow consumers to use the subscription. This configuration means that it is possible to have a subscription policy that only allows a 'Read' action from a subscription, because the creation of the subscription is handled by the administrative subscription.
Subscription monitoring results include a ConfigType field for subscriptions that have an associated configuration object. The ConfigType can be set to either AdminSubscription, DurableNamespaceAdminSub, or NonpersistentAdminSub so that a user can see which object type is associated with the subscription.
To delete a subscription that has an associated configuration type, use the configuration/ConfigType interface to ensure that the configuration and engine view of the subscriptions is consistent. Using the service/Subscription interface to delete the subscription generates an error message.
When deleting a subscription, the additional query parameter, DiscardSharers, can be set to either false or true. A value of false means that the delete request stops the subscription from having an associated ConfigType, so that the subscription is deleted when all clients stop sharing it. A value of true additionally discards sharers, so the subscription is deleted. The default value is false.
The following example shows a GET method to list MQTTv5 style $share shared subscriptions by using cURL:
curl -X GET \
-m 10 \
-u "admin:admin" \
-k \
https://127.0.0.1:9089/ima/v1/configuration/AdminSubscription
The following example shows a POST method to create an MQTTv5 style $share shared subscription by using cURL:
curl -X POST \
-m 10 \
-u "admin:admin" \
-k \
-d '
{"AdminSubscription":
{"/MySubShareName/Topic1/Topic2/Topic3/#":
{"SubscriptionPolicy":"MySubscriptionPolicy"}
}
}
' \
https://127.0.0.1:9089/ima/v1/configuration
The following example shows a GET method to view MQTTv5 style $share shared subscriptions by using cURL:
curl -X GET \
-m 10 \
-u "admin:admin" \
-k \
http://127.0.0.1:9089/ima/v1/configuration/AdminSubscription/MySubShareName/Topic1/Topic2/Topic3/%23
The following example shows a DELETE method to delete an MQTTv5 style $share shared subscription by using cURL:
curl -X DELETE \
-m 10 \
-u "admin:admin" \
-k \
http://127.0.0.1:9089/ima/v1/configuration/AdminSubscription/MySubShareName?DiscardSharers=false
The following example shows a GET method to list $SharedSubscription style durable shared subscription by using cURL:
curl -X GET \
-m 10 \
-u "admin:admin" \
-k \
https://127.0.0.1:9089/ima/v1/configuration/DurableNamespaceAdminSub
The following example shows a POST method to create a $SharedSubscription style durable shared subscription by using cURL:
curl -X POST \
-m 10 \
-u "admin:admin" \
-k \
-d '
{"DurableNamespaceAdminSub":
{ "MyDNSubShareName":
{"SubscriptionPolicy":"DemoSubscriptionPolicy",
"TopicFilter": "Topic1/Topic2/Topic3/#"
}
}
}
' \
https://127.0.0.1:9089/ima/v1/configuration
The following example shows a GET method to view $SharedSubscription style durable shared subscriptions by using cURL:
curl -X GET \
-m 10 \
-u "admin:admin" \
-k \
http://127.0.0.1:9089/ima/v1/configuration/DurableNamespaceAdminSub/MyDNSubShareName
The following example shows a DELETE method to delete a $SharedSubscription style durable shared subscription by using cURL:
curl -X DELETE \
-m 10 \
-u "admin:admin" \
-k \
http://127.0.0.1:9089/ima/v1/configuration/DurableNamespaceAdminSub/MyDNSubShareName?DiscardSharers=false