# Using a transaction listener with an embedded instance

**URL:** <https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633>\
**Category:** Support\
**Created:** [May 2, 2019, 10:04am UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633 "2019-05-02T10:04:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavideRossi](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@DavideRossi](https://community.stardog.com/u/DavideRossi)\
**Post date:** [May 2, 2019, 10:04am UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/1 "2019-05-02T10:04:14Z")

</div>

Hi, after a bit of struggling with Maven I'm now able to run an application using an embedded Stardog.  
Now I'd like to attach a transaction listener to it.  
I see there is a good example here: [stardog-examples/examples/connectable at develop · stardog-union/stardog-examples · GitHub](https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable) however I cannot understand how to attach the listener to the embedded instance of Stardog I just created. I see the example uses a guice to inject the the listener but the missing part is how to use the injector configured with this module: [ExampleModule.java](https://github.com/stardog-union/stardog-examples/blob/develop/examples/connectable/main/src/com/complexible/stardog/examples/connectable/listener/ExampleModule.java).  
Should the injector configured with that module return a Connection, an AdminConnection?  
Do you have a simple two-liners to show how to use it?

BTW the link to " 9. Transaction Listener" in List of Examples here [GitHub - stardog-union/stardog-examples: Examples for working with and extending Stardog](https://github.com/stardog-union/stardog-examples) is wrong (404).

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [May 2, 2019, 10:43am UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/2 "2019-05-02T10:43:48Z")

</div>

I don’t believed that the listener is defined for a specific connection but listens on all connections. It will be looked up my the service definition and injected. There shouldn’t be anything specific you need to do for embedded mode. It’s all automagic.

---

<div class="post-metadata">

**Author:** ![DavideRossi](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@DavideRossi](https://community.stardog.com/u/DavideRossi)\
**Post date:** [May 2, 2019, 11:06am UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/3 "2019-05-02T11:06:13Z")

</div>

But do I have to create an Injector or I don't?

---

<div class="post-metadata">

**Author:** ![evren](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/evren/32/1515_2.png) [@evren](https://community.stardog.com/u/evren)\
**Post date:** [May 2, 2019, 11:30am UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/4 "2019-05-02T11:30:14Z")

</div>

The example you refer to is for an embedded connection already. You need the Guice module definition as in that example but do not need to create an injector explicitly which is done by Stardog internals. You need the service loader file [1] so Stardog will include use your Guice module.

Best,  
Evren

[1] [stardog-examples/examples/connectable/main/resources/META-INF/services at develop · stardog-union/stardog-examples · GitHub](https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable/main/resources/META-INF/services)

---

<div class="post-metadata">

**Author:** ![DavideRossi](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@DavideRossi](https://community.stardog.com/u/DavideRossi)\
**Post date:** [May 2, 2019, 1:01pm UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/5 "2019-05-02T13:01:01Z")

</div>

Gotcha. That was the piece I was missing. Thanks.

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [May 3, 2019, 12:44pm UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/6 "2019-05-03T12:44:01Z")

</div>

> [@DavideRossi](#):
>
> BTW the link to " 9. Transaction Listener" in List of Examples here [https://github.com/stardog-union/stardog-examples](https://github.com/stardog-union/stardog-examples) is wrong (404).

The correct link would most likely be [https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable](https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [May 17, 2019, 12:51pm UTC](https://community.stardog.com/t/using-a-transaction-listener-with-an-embedded-instance/1633/7 "2019-05-17T12:51:25Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
