Metric wildcards and default attributes
This commit is contained in:
parent
2278d98824
commit
8e20fd8800
@ -233,7 +233,7 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
try {
|
try {
|
||||||
List<TransportProtos.PostTelemetryMsg> msgs = new ArrayList<>();
|
List<TransportProtos.PostTelemetryMsg> msgs = new ArrayList<>();
|
||||||
for (SparkplugBProto.Payload.Metric protoMetric : sparkplugBProto.getMetricsList()) {
|
for (SparkplugBProto.Payload.Metric protoMetric : sparkplugBProto.getMetricsList()) {
|
||||||
if (attributesMetricNames == null || !attributesMetricNames.contains(protoMetric.getName())) {
|
if (attributesMetricNames == null || !matches(attributesMetricNames, protoMetric)) {
|
||||||
long ts = protoMetric.getTimestamp();
|
long ts = protoMetric.getTimestamp();
|
||||||
String key = "bdSeq".equals(protoMetric.getName()) ?
|
String key = "bdSeq".equals(protoMetric.getName()) ?
|
||||||
topicTypeName + " " + protoMetric.getName() : protoMetric.getName();
|
topicTypeName + " " + protoMetric.getName() : protoMetric.getName();
|
||||||
@ -264,7 +264,7 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
try {
|
try {
|
||||||
List<TransportApiProtos.AttributesMsg> msgs = new ArrayList<>();
|
List<TransportApiProtos.AttributesMsg> msgs = new ArrayList<>();
|
||||||
for (SparkplugBProto.Payload.Metric protoMetric : sparkplugBProto.getMetricsList()) {
|
for (SparkplugBProto.Payload.Metric protoMetric : sparkplugBProto.getMetricsList()) {
|
||||||
if (attributesMetricNames.contains(protoMetric.getName())) {
|
if (matches(attributesMetricNames, protoMetric)) {
|
||||||
TransportApiProtos.AttributesMsg.Builder deviceAttributesMsgBuilder = TransportApiProtos.AttributesMsg.newBuilder();
|
TransportApiProtos.AttributesMsg.Builder deviceAttributesMsgBuilder = TransportApiProtos.AttributesMsg.newBuilder();
|
||||||
Optional<TransportProtos.PostAttributeMsg> msgOpt = getPostAttributeMsg(protoMetric);
|
Optional<TransportProtos.PostAttributeMsg> msgOpt = getPostAttributeMsg(protoMetric);
|
||||||
if (msgOpt.isPresent()) {
|
if (msgOpt.isPresent()) {
|
||||||
@ -281,6 +281,18 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean matches(Set<String> attributesMetricNames, SparkplugBProto.Payload.Metric protoMetric) {
|
||||||
|
String metricName = protoMetric.getName();
|
||||||
|
for (String attributeMetricFilter : attributesMetricNames) {
|
||||||
|
if (metricName.equals(attributeMetricFilter) ||
|
||||||
|
(attributeMetricFilter.endsWith("*") && metricName.startsWith(
|
||||||
|
attributeMetricFilter.substring(0, attributeMetricFilter.length() - 1)))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private Optional<TransportProtos.PostAttributeMsg> getPostAttributeMsg(SparkplugBProto.Payload.Metric protoMetric) throws ThingsboardException {
|
private Optional<TransportProtos.PostAttributeMsg> getPostAttributeMsg(SparkplugBProto.Payload.Metric protoMetric) throws ThingsboardException {
|
||||||
Optional<TransportProtos.KeyValueProto> keyValueProtoOpt = fromSparkplugBMetricToKeyValueProto(protoMetric.getName(), protoMetric);
|
Optional<TransportProtos.KeyValueProto> keyValueProtoOpt = fromSparkplugBMetricToKeyValueProto(protoMetric.getName(), protoMetric);
|
||||||
if (keyValueProtoOpt.isPresent()) {
|
if (keyValueProtoOpt.isPresent()) {
|
||||||
|
|||||||
@ -368,6 +368,7 @@ export function createDeviceProfileTransportConfiguration(type: DeviceTransportT
|
|||||||
deviceAttributesTopic: 'v1/devices/me/attributes',
|
deviceAttributesTopic: 'v1/devices/me/attributes',
|
||||||
deviceAttributesSubscribeTopic: 'v1/devices/me/attributes',
|
deviceAttributesSubscribeTopic: 'v1/devices/me/attributes',
|
||||||
sparkplug: false,
|
sparkplug: false,
|
||||||
|
sparkplugAttributesMetricNames: ['Node Control/*', 'Device Control/*', 'Properties/*'],
|
||||||
sendAckOnValidationException: false,
|
sendAckOnValidationException: false,
|
||||||
transportPayloadTypeConfiguration: {
|
transportPayloadTypeConfiguration: {
|
||||||
transportPayloadType: TransportPayloadType.JSON,
|
transportPayloadType: TransportPayloadType.JSON,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user