# Reading tag values in Gateway (Subscribing to Tags)

**URL:** <https://forum.inductiveautomation.com/t/reading-tag-values-in-gateway-subscribing-to-tags/12232>\
**Category:** Module Development\
**Created:** [October 13, 2016, 1:10pm UTC](https://forum.inductiveautomation.com/t/reading-tag-values-in-gateway-subscribing-to-tags/12232 "2016-10-13T13:10:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Mmacerl](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmacerl/32/4024_2.png) [@Mmacerl](https://forum.inductiveautomation.com/u/Mmacerl)\
**Post date:** [October 14, 2016, 10:53am UTC](https://forum.inductiveautomation.com/t/reading-tag-values-in-gateway-subscribing-to-tags/12232/2 "2016-10-14T10:53:19Z")

</div>

I figured out how to read tag values so I am posting the solution here in case someone will be struggling with this like I was.

1. First of all you need to make new class implementing TagChangeListener

```auto
public class TagListener implements TagChangeListener {
	TagPath path;
	public TagListener(TagPath path) {
		this.path= path;
		// TODO Auto-generated constructor stub
	}

	private final Logger log = Logger.getLogger(getClass());

	@Override
	public TagProp getTagProperty() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void tagChanged(TagChangeEvent arg0) {
		List <TagPath> list= new ArrayList<TagPath>();
		list.add(path);
		List<QualifiedValue> tags= GatewayHook.context.getTagManager().read(list);
		log.error("Value : "+ tags.get(0).getValue());
	}
}
```

With overriding the “tagChanged” function you define what should happen when the tag changes.

1. Than you use the “TagManager” provided by the context you are in to subscribe to the wanted tag.

```auto
public void readingTest() throws IOException{
		TagPath myPath= TagPathParser.parse("[default]underTag/TestniTag");
		TagListener listener=new TagListener(myPath) {

		};
		List <TagPath> lista= new ArrayList<TagPath>();
		lista.add(myPath);
		GatewayHook.context.getTagManager().subscribe(myPath, listener);
		
	}
```

---

_[View the full topic](https://forum.inductiveautomation.com/t/reading-tag-values-in-gateway-subscribing-to-tags/12232)._
