What are Extensions?
HiveMQ Community Edition extensions allow you to customize and extend the MQTT broker’s functionality using Java. Extensions enable you to implement custom business logic for:- Authentication - Verify client identities using custom credential sources
- Authorization - Control publish and subscribe permissions
- Client Initialization - Set up client-specific context when clients connect
- Packet Interception - Intercept and modify MQTT packets
- Event Handling - React to client lifecycle events
Extension System Architecture
Extensions run within HiveMQ’s extension system, which provides:- Isolated Class Loading - Each extension runs in its own classloader
- Lifecycle Management - Extensions are started and stopped automatically
- Service APIs - Access to HiveMQ services for clients, subscriptions, and retained messages
- Asynchronous Processing - Non-blocking execution for high performance
Extension Structure
Every extension consists of:Extension Descriptor
Ahivemq-extension.xml file that defines extension metadata:
id- Unique extension identifierversion- Extension version numbername- Human-readable extension nameauthor- Extension authorpriority- Execution priority (lower = higher priority)start-priority- Startup order priority
Extension Main Class
A Java class implementingExtensionMain from the HiveMQ Extension SDK:
HiveMQExtension.java:41 for the internal interface definition.
Extension Deployment
Standalone Deployment
- Package your extension as a JAR file with dependencies
- Create the
hivemq-extension.xmldescriptor - Place both files in a folder under
<hivemq>/extensions/<extension-id>/ - HiveMQ will automatically load and start the extension
Embedded Deployment
For programmatic deployment in embedded mode:README.adoc:233 for embedded extension examples.
Extension Services
The Extension SDK provides access to HiveMQ services through theExtensionStartInput:
Extension Priorities
Extensions execute in priority order:- Priority (
priorityfield) - Controls execution order for authenticators, authorizers, and interceptors- Lower numbers execute first (e.g., priority 0 before priority 100)
- Default: 0
- Start Priority (
start-priorityfield) - Controls extension startup order- Higher numbers start first (e.g., 1000 before 0)
- Default: 1000
HiveMQExtension.java:72-78 for priority interface methods.
Extension Examples
Allow-All Extension
HiveMQ includes an allow-all extension for development: Location:src/distribution/extensions/hivemq-allow-all-extension/
Configuration: hivemq-allow-all-extension/hivemq-extension.xml:1
This extension allows all connections and operations without authentication.
Best Practices
Performance
- Use Asynchronous Processing - Avoid blocking operations in callbacks
- Minimize Latency - Keep authentication and authorization logic fast
- Cache When Possible - Cache credential lookups and authorization decisions
- Use Thread Pools - Leverage the managed executor service for background tasks
Security
- Validate All Inputs - Never trust client-provided data
- Use Secure Credential Storage - Never hardcode credentials
- Implement Proper Error Handling - Don’t leak sensitive information in errors
- Follow Least Privilege - Grant minimum necessary permissions
Reliability
- Handle Failures Gracefully - Implement fallback behavior
- Log Appropriately - Use structured logging for debugging
- Test Thoroughly - Unit test and integration test extensions
- Monitor Extension Health - Track extension metrics and errors
Troubleshooting
Extension Not Loading
- Verify
hivemq-extension.xmlis valid XML - Check extension ID matches folder name
- Ensure JAR contains all dependencies
- Review HiveMQ logs for classloading errors
Runtime Errors
- Check for exceptions in HiveMQ logs
- Verify SDK version compatibility
- Review thread safety of shared state
- Enable debug logging for extension system
Next Steps
Extension SDK
Learn about the Extension SDK API and dependencies
Authentication
Implement custom authentication logic
Authorization
Control client permissions
Packet Interceptors
Intercept and modify MQTT packets