[Module Development] How do I subscribe to tag change events in the Gateway?

I am trying to create a module for Ignition to expose tag changes over a websocket to a custom-built client but none of the resources are up to date/exhaustive enough for 8.1.

Setting up the servlet was enough of a struggle just trying to figure out first how to add the servlet to the gateway, but then also what path that mapped out to (took a few articles here to figure out the path structure).

Once the socket was set up, I had to get the tag events. I saw on another discussion that a user was told to use the ManagedTagProvider class as it has replaced the previous SQLTags implementation which was marked as deprecated, however there is no functionality for reading a tag, getting a list of tags, or anything resembling a read operation for tags in that class. Which makes me wonder why it was suggested in the first place if the implementation is incomplete.

When that didn't work, I tried creating an ad-hoc FilteredTagChangeListener and subscribing to needed change events over the websocket looking like the following...

TagPath tag_path = TagPathParser.parse("default", path);

FilteredTagChangeListener listener = new FilteredTagChangeListener(tag_path,
                EnumSet.of(FilteredTagChangeListener.TagChangeType.ValueChange),
                new GatewayTagChangeListenerDelegate());
public class GatewayTagChangeListenerDelegate implements TagChangeListener {

    @Override
    public void tagChanged(TagChangeEvent tagChangeEvent) throws InvalidListenerException {
        TagChangeEntity entity = new TagChangeEntity();
        Gson gson = new Gson();
        Logger logger;

        entity.type = "change";
        entity.tag_path = tagChangeEvent.getTagPath().toStringFull();
        entity.value = tagChangeEvent.getValue().getValue();

        logger = LogManager.getLogger(getClass());

        logger.info("Subscribed tag change for tag \"" + entity.tag_path + "\". Value: " + entity.value.toString());

        // More code for sending to subscribed clients
    }

    @Override
    public boolean isLightweight() {
        return TagChangeListener.super.isLightweight();
    }
}

But I never get the trigger for the tag change. How are you supposed to do this in 8.1?

It's not going to be well documented, but it's fairly straightforward and pretty much the same as it would have been in 7.9

Get the GatewayTagManager from GatewayContext::getTagManager. Use one of the subscribe methods on it to subscribe to change events for a tag path.

1 Like

Thanks for the quick help Kevin, this is indeed pretty straight forward once you know what to look for. Glad I can move another step closer to completing this module