Declared Shared Subscriptions Configuration on HiveMQ Platform
Declared shared subscriptions let HiveMQ enqueue messages for preconfigured shared subscriptions as soon as the broker starts, even when no shared subscriber is connected. HiveMQ reads them from a declared-shared-subscriptions.xml file in its configuration folder. The file must be present before HiveMQ starts, and it must be identical on every node of the cluster. See Declared Shared Subscriptions.
When HiveMQ is deployed with the HiveMQ Platform Operator, the configuration folder (/opt/hivemq/conf-k8s/) is populated from the HiveMQ Platform configuration ConfigMap. The ConfigMap that the hivemq-platform Helm chart creates contains only config.xml and tracing.xml. To add declared-shared-subscriptions.xml, provide your own configuration ConfigMap that contains all three files. No StatefulSet override is required.
Prerequisites
Kubernetes 1.24 or higher
Helm 3.10.x or higher (Helm 4.x is also supported)
HiveMQ Platform Operator installed with the
hivemq/hivemq-platform-operatorchartHiveMQ Platform deployed (or ready to deploy) with the
hivemq/hivemq-platformchart
This article was verified with hivemq/hivemq-platform-operator 0.2.28 (operator 2.3.1) and hivemq/hivemq-platform 0.3.3 (HiveMQ 4.56.1). In the examples, the namespace is hivemq, the HiveMQ Platform release name is platform, and the custom ConfigMap is named my-config.
Instructions
Generate a starting ConfigMap from the chart. Render the configuration ConfigMap that the chart would create with your current values. The
--set config.create=trueflag ensures that the ConfigMap is rendered even after you have switched to a custom ConfigMap:
helm template platform hivemq/hivemq-platform -n hivemq -f values.yaml \
--set config.create=true \
--show-only templates/hivemq-configuration.yml > cm-my-config.yamlEdit
cm-my-config.yaml. Changemetadata.nametomy-config, remove thehelm.sh/chartandapp.kubernetes.io/managed-by: Helmlabels, and add adeclared-shared-subscriptions.xmlkey next to the existingconfig.xmlandtracing.xmlkeys:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
namespace: hivemq
data:
config.xml: |-
<?xml version="1.0"?>
<hivemq xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd">
... (generated content, unchanged) ...
</hivemq>
tracing.xml: |-
... (generated content, unchanged) ...
declared-shared-subscriptions.xml: |-
<?xml version="1.0"?>
<declared-shared-subscriptions>
<subscription>
<topic-filter>device/status</topic-filter>
<share-name>group1</share-name>
</subscription>
<subscription>
<topic-filter>device/update</topic-filter>
<share-name>group2</share-name>
</subscription>
</declared-shared-subscriptions>Create the ConfigMap:
kubectl apply -f cm-my-config.yamlUpdate the HiveMQ Platform values.yaml so that the chart uses your ConfigMap instead of creating its own:
config:
create: false
name: "my-config"create: false: The chart does not create the default configuration ConfigMap.name: "my-config": The name of the ConfigMap that containsconfig.xml,tracing.xml, anddeclared-shared-subscriptions.xml.
With config.create: false, chart values that render into the HiveMQ configuration are no longer applied. This includes the listeners for services, config.dataHub, dataIntelligence, and config.customLogbackConfig. Kubernetes Services are still created from services, but the matching HiveMQ listeners must exist in your config.xml. When you change these values, regenerate the file with Step 1, re-add the declared-shared-subscriptions.xml key, and apply the ConfigMap again.
Deploy the updated HiveMQ Platform:
helm upgrade --install platform hivemq/hivemq-platform -n hivemq -f values.yamlVerify the configuration. Confirm that
declared-shared-subscriptions.xmlis present in/opt/hivemq/conf-k8s/in the HiveMQ pods:
kubectl exec pods/platform-0 -n hivemq -c hivemq -- \
ls -la /opt/hivemq/conf-k8s/declared-shared-subscriptions.xmlCheck the HiveMQ log. Confirm that HiveMQ loaded the declared shared subscriptions:
kubectl logs pods/platform-0 -n hivemq -c hivemq | grep -i declaredINFO - Declared shared subscriptions from file /opt/hivemq/conf-k8s/declared-shared-subscriptions.xmlIf the file is invalid or malformed, HiveMQ logs an error and does not start.
Future configuration updates
Declared shared subscriptions cannot be changed at runtime. To change them, edit cm-my-config.yaml and apply it again:
kubectl apply -f cm-my-config.yamlHiveMQ reads declared-shared-subscriptions.xml only at startup, so a rolling restart of the HiveMQ pods is required for the change to take effect. If the change does not trigger a rolling restart automatically, trigger one as described in Restart a cluster best practice. Because every pod mounts the same ConfigMap, all nodes end up with an identical declared-shared-subscriptions.xml.
By following these steps, you can add declared-shared-subscriptions.xml to a HiveMQ Platform deployment on Kubernetes without overriding the StatefulSet.