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

**URL:** <https://forum.inductiveautomation.com/t/module-development-how-do-i-subscribe-to-tag-change-events-in-the-gateway/79948>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [October 2, 2023, 7:28pm UTC](https://forum.inductiveautomation.com/t/module-development-how-do-i-subscribe-to-tag-change-events-in-the-gateway/79948 "2023-10-02T19:28:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_McLean](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tyler\_McLean](https://forum.inductiveautomation.com/u/Tyler_McLean)\
**Post date:** [October 2, 2023, 7:28pm UTC](https://forum.inductiveautomation.com/t/module-development-how-do-i-subscribe-to-tag-change-events-in-the-gateway/79948/1 "2023-10-02T19:28:48Z")

</div>

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...

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

FilteredTagChangeListener listener = new FilteredTagChangeListener(tag_path,
                EnumSet.of(FilteredTagChangeListener.TagChangeType.ValueChange),
                new GatewayTagChangeListenerDelegate());

```

```auto
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?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 2, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/module-development-how-do-i-subscribe-to-tag-change-events-in-the-gateway/79948/2 "2023-10-02T19:37:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tyler\_McLean](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tyler\_McLean](https://forum.inductiveautomation.com/u/Tyler_McLean)\
**Post date:** [October 2, 2023, 8:06pm UTC](https://forum.inductiveautomation.com/t/module-development-how-do-i-subscribe-to-tag-change-events-in-the-gateway/79948/3 "2023-10-02T20:06:36Z")

</div>

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
