在路由配置中添加一个自定义的消息变换器(Message Transformer),该变换器在路由模块间传递消息时,将自定义属性添加到传递的消息中。以下是示例代码:
{
"routes": {
"route1": "FROM /messages/* INTO BrokeredEndpoint(\"/modules/module1/inputs/input1\")",
"route2": "FROM /messages/* INTO BrokeredEndpoint(\"/modules/module2/inputs/input1\")"
},
"schemaVersion": "1.0",
"extensions": {
"route1": {
"properties": {
"customProperty1": "value1"
}
},
"route2": {
"properties": {
"customProperty2": "value2"
}
}
},
"stores": {
"customMsgPropTransformer": {
"type": "custom",
"image": "customMsgPropTransformer:latest",
"env": {
"CUSTOM_PROP1": "$(extension.route1.properties.customProperty1)",
"CUSTOM_PROP2": "$(extension.route2.properties.customProperty2)"
},
"version": "1.0",
"status": "running"
}
},
"moduleToModuleCommunication": {
"customMsgPropRoute": [
{
"source": "/modules/module1/outputs/output1",
"sink": "/modules/module2/inputs/input1",
"route": {
"name": "customMsgPropRoute",
"store": "customMsgPropTransformer"
}
}
]
}
}
在此示例中,我们定义了两个路由:route1和route2,它们都包含自定义属性。我们还定义了一个名为customMsgPropTransformer的自定义变换器,该变换器从这些路由的扩展中提取属性并将其添加到传递的消息中。最后,我们将这个消息变换器作为路由定义在moduleToModuleCommunication部分中。