简体   繁体   English

正确解释事件的服务器响应

[英]Interpreting server response for events correclty

I would like to store values of event properties received from the server in a database.我想将从服务器接收到的事件属性值存储在数据库中。 My problems are that in the event consumer:我的问题是事件消费者:

  1. I cant figure out which eventtype my client received.我无法弄清楚我的客户收到了哪种事件类型。
  2. I dont know how to map variant indexes to properties without knowing the EventType.我不知道如何在不知道 EventType 的情况下将 map 变体索引到属性。

Events come with the property "EventType", which would solve my first problem.事件带有属性“EventType”,这将解决我的第一个问题。 But since I am receiving many different event types, I do not know in which variant index it is located.但由于我收到许多不同的事件类型,我不知道它位于哪个变体索引中。 Should I always relocate "EventType" at index 0 in the select clause whenever creating a new EventFilter?每当创建新的 EventFilter 时,我是否应该始终在 select 子句中的索引 0 处重新定位“EventType”?

For the second problem, item.getMonitoringFilter().decode(client.getSerializationContext())) offers a view on the property structure but I am not sure how to use it for mapping of variants to properties.对于第二个问题, item.getMonitoringFilter().decode(client.getSerializationContext())) 提供了关于属性结构的视图,但我不确定如何使用它来将变体映射到属性。 Does anybody know how to solve those problems?有人知道如何解决这些问题吗?

Here is the event consumer code that I use.这是我使用的事件消费者代码。 It is taken from milo client examples.它取自 milo 客户端示例。

for (UaMonitoredItem monitoredItem: mItems){
                monitoredItem.setEventConsumer((item, vs) -> {
                    LOGGER.info(
                        "Event Received from: {}", item.getReadValueId().getNodeId());
                    LOGGER.info(
                        "getMonitoredItemId: {}", item.getMonitoredItemId());
                    LOGGER.info(
                        "getMonitoringFilter: {}", item.getMonitoringFilter().decode(client.getSerializationContext()));
                    for (int i = 0; i < vs.length; i++) {
                        LOGGER.info("variant[{}]:, datatype={}, value={}", i, vs[i].getDataType(), vs[i].getValue());
                    }
                });
            }

Thank you in advance.先感谢您。

Update:更新:

Seems I have figured it out, by typcasting to EventFilter.似乎我已经弄清楚了,通过对 EventFilter 进行类型转换。 Further information such as qName for event properties or event type node IDs can then be derived:然后可以导出更多信息,例如事件属性的 qName 或事件类型节点 ID:

ExtensionObject eObject = item.getMonitoringFilter();
EventFilter eFilter = ((EventFilter) eObject.decode(client.getSerializationContext()));
QualifiedName qName = eFilter.getSelectClauses()[0].getBrowsePath()[0];

LiteralOperand literalOperand  = (LiteralOperand) eFilter.getWhereClause().getElements()[0]
        .getFilterOperands()[1].decode(client.getSerializationContext());
NodeId eventTypeNodeId = (NodeId) literalOperand.getValue().getValue();

Didn't you supply the filter in the first place when you created the MonitoredItem?您在创建 MonitoredItem 时没有首先提供过滤器吗? Why do you need to "reverse engineer" the filter result to get back to what you did in the first place?为什么您需要对过滤结果进行“逆向工程”以恢复您最初所做的事情?

The properties you receive in the event data and the order they come in are defined by the select clause you used when creating the MonitoredItem.您在事件数据中收到的属性及其进入顺序由您在创建 MonitoredItem 时使用的 select 子句定义。 If you choose to select the EventId field then it will always be at the same corresponding index.如果您选择 select EventId 字段,那么它将始终位于相同的相应索引处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM