Subscribing to tag change events
This section explains how to subscribe to tag change events.
Overview
A tag change event is a message that contains a time stamp, and a list of tag identifiers whose values have changed. For each tag identifier, a new value of the tag is also returned.
You can subscribe to tag change events by using the TagProvider
service methods. This service is defined in the tag_provider_service.proto
file. Messages and enumerations are defined in the tag_provider.proto
, tag_provider_service.proto
, and common.proto
files.
The TagProvider
service has the following methods for subscribing to tag change events:
SubscribeTagNotifier
Subscribes to tag change events.
You can specify a list of tag identifiers. Only events for the specified identifiers will be included in the subscription.
UnsubscribeNotifier
Removes an existing subscription.
Subscribing to tag change events (example)
To subscribe to tags, use the SubscribeTagNotifier
method. In the following example, a stub makes a subscription request for tags with identifiers 1000
, 1001
, and 1002
. Kaspersky Industrial CyberSecurity for Networks API will send events to the client.example.com:50051
address and port, where they must be handled by the TagNotifier
service. After that, the stub waits for 10 seconds and unsubscribes from tag change events.
tagStub = tag_provider_service_pb2_grpc.TagProviderStub(channel)
#rpc SubscribeTagNotifier(SubscriptionRequest) returns(Cookie); #rpc UnsubscribeNotifier(Cookie) returns(google.protobuf.Empty);
listener = "client.example.com:50051"
tag_filter = tag_provider_service_pb2.Filter(tagIds=[1000, 1001, 1002])
request = tag_provider_service_pb2.SubscriptionRequest(address=listener, filter=tag_filter) response = tagStub.SubscribeTagNotifier(request) cookie = response.cookie
# wait for 10 seconds, then unsubscribe print("Sleeping for 10 seconds") time.sleep(10)
# unsubscribe print("Unsubscribing") request = common_pb2.Cookie(cookie=cookie) response = tagStub.UnsubscribeNotifier(request) |