首页 > 解决方案 > 如何删除 Eclipse Milo 0.3.8 中的订阅项目?

问题描述

我查看了订阅 NodeId 的示例,我想知道之后如何停止/删除订阅。

Eclipse Milo v0.3.8 客户端。

这是我尝试过的。

  protected boolean unsubscribe(TransactionDefinition transactionDefinition) {

// Finds the mathing TransactionDefinition from the map where all subscriptions 
// are stored, together with the clientHandle. 
// private Map<UInteger, TransactionDefinition> subscriptions = new HashMap<>();
try {
  UInteger subscriptionClientHandle = null;
  for (Map.Entry<UInteger, TransactionDefinition> entry : subscriptions.entrySet()) {
    if (entry.getValue().equals(transactionDefinition))
      subscriptionClientHandle = entry.getKey();
  }
  if (subscriptionClientHandle == null) return false;

  try {
    client.getSubscriptionManager().deleteSubscription(subscriptionClientHandle).get();
    return true;
  } catch (Exception e) {
    log.error("Subscription not found: {}", e.getMessage(), e.getCause());
    e.printStackTrace();
  }

} catch (ClassCastException e) {
  log.error("TransactionDefinition trigger not found. {}", e.getMessage(), e.getCause());
  e.printStackTrace();
}
return false;

}

标签: opc-uamilo

解决方案


UaSubscription有一个deleteMonitoredItems方法。

UaSubscriptionManager有一个deleteSubscription方法。

UaClient您还可以通过在实例上调用“原始”服务方法来“手动”调用这些服务中的任何一个。


推荐阅读