From a4948a06f1cdcce7c4879ec044981cee345c9fe7 Mon Sep 17 00:00:00 2001 From: Jeremy Theocharis Date: Wed, 18 Dec 2024 15:52:13 +0000 Subject: [PATCH 1/3] added one more example --- README.md | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/README.md b/README.md index 713959a..8e25bb6 100644 --- a/README.md +++ b/README.md @@ -1470,6 +1470,102 @@ Output 2 (custom): ``` Topic: `umh.v1.enterprise.production._custom.temperature_doubled` +6. **Processing Full MQTT Message Payload** +```yaml +tag_processor: + defaults: | + msg.meta.location_path = "enterprise.area._workorder"; + msg.meta.data_contract = "_workorder"; + msg.meta.virtual_path = "new"; + msg.meta.tag_name = "maintenance"; + return msg; +``` + +Input: +```json +{ + "maintenanceSchedule": { + "eventType": "ScheduledMaintenance", + "eventId": "SM-20240717-025", + "timestamp": "2024-07-17T13:00:00Z", + "equipmentId": "InjectionMoldingMachine5", + "equipmentName": "Engel Victory 120", + "scheduledDate": "2024-07-22", + "maintenanceType": "Preventive", + "description": "Inspection and cleaning of injection unit and mold.", + "maintenanceDuration": "6 hours", + "assignedTo": { + "employeeId": "EMP-5005", + "name": "Hans Becker" + }, + "status": "Scheduled", + "partsRequired": [ + { + "partId": "NOZZLE-015", + "description": "Injection Nozzle", + "quantity": 1 + } + ], + "notes": "Replace worn nozzle to prevent defects." + } +} +``` + +Output: +```json +{ + "maintenance": { + "maintenanceSchedule": { + "eventType": "ScheduledMaintenance", + "eventId": "SM-20240717-025", + "timestamp": "2024-07-17T13:00:00Z", + "equipmentId": "InjectionMoldingMachine5", + "equipmentName": "Engel Victory 120", + "scheduledDate": "2024-07-22", + "maintenanceType": "Preventive", + "description": "Inspection and cleaning of injection unit and mold.", + "maintenanceDuration": "6 hours", + "assignedTo": { + "employeeId": "EMP-5005", + "name": "Hans Becker" + }, + "status": "Scheduled", + "partsRequired": [ + { + "partId": "NOZZLE-015", + "description": "Injection Nozzle", + "quantity": 1 + } + ], + "notes": "Replace worn nozzle to prevent defects." + } + + }, + "timestamp_ms": 1733903611000 +} +``` +Topic: `umh.v1.enterprise.area._workorder.maintenance` + +**Note:** In the `tag_processor`, the resulting payload will always include `timestamp_ms` and one additional key corresponding to the `tag_name`. If you need to fully control the resulting payload structure, consider using the `nodered_js` processor instead. You can set the topic and payload manually, as shown below: + +```yaml +pipeline: + processors: + - nodered_js: + code: | + // set kafka topic manually + msg.meta.topic = "umh.v1.enterprise.site.area._workorder.new" + + // only take two fields from the payload + msg.meta.payload = { + "maintenanceSchedule": { + "eventType": msg.payload.maintenanceSchedule.eventType, + "description": msg.payload.maintenanceSchedule.description + } + } + return msg; +``` + ## Testing We execute automated tests and verify that benthos-umh works against various targets. All tests are started with `make test`, but might require environment parameters in order to not be skipped. From 48ad3095d47b840554b50795d8d7baacc8af1705 Mon Sep 17 00:00:00 2001 From: Jeremy Theocharis Date: Wed, 18 Dec 2024 15:59:11 +0000 Subject: [PATCH 2/3] added when to use what --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8e25bb6..3ca7691 100644 --- a/README.md +++ b/README.md @@ -746,6 +746,8 @@ Similar to the OPC UA input, this outputs for each address a single message with The Node-RED JavaScript processor allows you to write JavaScript code to process messages in a style similar to Node-RED function nodes. This makes it easy to port existing Node-RED functions to Benthos or write new processing logic using familiar JavaScript syntax. +Use the `nodered_js` processor instead of the `tag_processor` when you need full control over the payload and require custom processing logic that goes beyond standard tag or time series data handling. This processor allows you to write custom JavaScript code to manipulate both the payload and metadata, providing the flexibility to implement complex transformations, conditional logic, or integrate with other systems. + #### Configuration ```yaml @@ -1042,6 +1044,9 @@ Note that these benchmarks represent a simple operation. The performance differe The Tag Processor is designed to prepare incoming data for the UMH data model. It processes messages through three configurable stages: defaults, conditional transformations, and advanced processing, all using a Node-RED style JavaScript environment. +Use the `tag_processor` compared to the `nodered_js` when you are processing tags or time series data and converting them to the UMH data model within the `_historian` data contract. This processor is optimized for handling structured time series data, automatically formats messages, and generates appropriate metadata. + + #### Message Formatting Behavior The processor automatically formats different input types into a consistent structure with a "value" field: From 5f64fc66ac95d0885608db1f26a6b775f5d86233 Mon Sep 17 00:00:00 2001 From: Jeremy Theocharis Date: Thu, 16 Jan 2025 12:58:16 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b000a0..ec87eb6 100644 --- a/README.md +++ b/README.md @@ -1584,7 +1584,7 @@ pipeline: msg.meta.topic = "umh.v1.enterprise.site.area._workorder.new" // only take two fields from the payload - msg.meta.payload = { + msg.payload = { "maintenanceSchedule": { "eventType": msg.payload.maintenanceSchedule.eventType, "description": msg.payload.maintenanceSchedule.description