UMH Topic Parser
The UMH Topic Parser is a high-performance Go package that provides parsing, validation, and construction utilities for UMH (Unified Manufacturing Hub) topics. It ensures that all topics conform to the UMH specification and can be safely used as Kafka message keys.
Overview
UMH topics follow a strict hierarchical structure that represents the physical and logical organization of manufacturing systems. This package centralizes topic handling across all UMH components, providing consistent validation and preventing bad data from entering the UNS.
Topic Structure
UMH topics follow this format:
umh.v1.<location_path>.<data_contract>[.<virtual_path>].<name>Components:
location_path: 1-N hierarchical levels representing physical organization (enterprise.site.area.line...)
data_contract: Service/schema identifier starting with underscore (_historian, _analytics, etc.)
virtual_path: Optional logical grouping (axis.x.position, diagnostics.*, etc.)
name: Final identifier for the specific data point
Validation Rules
The package enforces these fixed rules:
Location path levels: MUST NOT start with underscore, at least 1 level required
Data contract: MUST start with underscore, cannot be just "_"
Virtual path: CAN start with underscore, optional
Name: CAN start with underscore, required
Kafka compatibility: Only
[a-zA-Z0-9._-]characters allowedNo consecutive dots, leading dots, or trailing dots
Examples
Valid Topics
Invalid Topics
Usage
Basic Parsing and Validation
Programmatic Construction
High-Performance Scenarios
For high-throughput scenarios, reuse builder instances:
Location Path Handling
Performance Characteristics
The package is optimized for high-throughput scenarios:
Simple topic parsing: ~656ns per operation
Complex topic parsing: ~1322ns per operation
Simple topic construction: ~751ns per operation
Complex topic construction: ~1436ns per operation
Memory allocations: 3-5 allocations per topic creation
Read operations: <1ns (String(), Info(), AsKafkaKey() are essentially free)
Thread Safety
UnsTopic instances: Immutable and safe for concurrent use
Builder instances: NOT thread-safe (use separate builders per goroutine)
Package-level functions: Thread-safe
Integration Patterns
Message Processing
Location-Based Routing
Bulk Topic Generation
Error Handling
The package provides detailed error messages for debugging:
Error messages include:
Specific validation rule that failed
Position information for parsing errors
Suggestions for common mistakes
Migration Guide
From Manual String Parsing
Before:
After:
From Existing Validation Code
The topic parser replaces manual validation logic throughout the codebase:
topic_browser_plugin: Replace
topicToUNSInfo()and manual parsinguns_output: Replace manual topic validation
tag_processor_plugin: Replace
constructUMHTopic()with Builderclassic_to_core_plugin: Replace manual topic parsing
API Reference
Core Types
Key Methods
Testing
The package includes comprehensive test coverage:
100+ test cases covering valid and invalid topics
Performance benchmarks for all operations
Concurrency tests for thread safety
Edge case validation for boundary conditions
Run tests:
Last updated

