# Configure Plugin through Cluster Settings API - Listen for updates

**URL:** <https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946>\
**Category:** Elasticsearch\
**Created:** [April 13, 2023, 6:05pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946 "2023-04-13T18:05:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smillies](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smillies/32/114371_2.png) [@smillies](https://discuss.elastic.co/u/smillies)\
**Post date:** [April 13, 2023, 6:05pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/1 "2023-04-13T18:05:24Z")

</div>

Hello there,

I am writing a plugin and would like to configure it through the cluster settings API.

I have overwritten getSettings, and so far so good. I can also update my dynamic settings through the cluster settings API.

However, the change never gets propagated to the plugin. I imagine that the plugin, or the setting, would have to register a listener to react to the update.

Can anyone provide guidance on this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2023, 6:35pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/2 "2023-04-13T18:35:18Z")

</div>

May be you need to send somehow a get cluster settings call from your plugin?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 13, 2023, 7:11pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/3 "2023-04-13T19:11:58Z")

</div>

`Plugin#getComponents` receives a `ClusterService`, and `ClusterService#getClusterSettings` yields a `ClusterSettings`, which has methods such as `initializeAndWatch` and `addSettingsUpdateConsumer` which allow you to register a listener for changes to particular cluster settings.

---

<div class="post-metadata">

**Author:** ![smillies](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smillies/32/114371_2.png) [@smillies](https://discuss.elastic.co/u/smillies)\
**Post date:** [April 13, 2023, 9:31pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/4 "2023-04-13T21:31:37Z")

</div>

Thank you!

```auto
@Override
public Collection<Object> createComponents(... ClusterService clusterService ...) {
	clusterService.getClusterSettings().addSettingsUpdateConsumer(
		settings -> updateMyDynamicSettings(settings), getSettings());
	return Collections.emptyList();
}

```

works. When I PUT host:9200/\_cluster/settings my update method is called.

(I'm getting some additional update events with unexpected setting values and I haven't figured out where they come from, but that must be a different problem.)

---

<div class="post-metadata">

**Author:** ![smillies](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smillies/32/114371_2.png) [@smillies](https://discuss.elastic.co/u/smillies)\
**Post date:** [April 13, 2023, 9:43pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/5 "2023-04-13T21:43:36Z")

</div>

`getSettings` would return some non-dynamic settings. Apparently, that seems to irritate the update logic. The spurious update events disappeared when I restricted the list of settings passed into `addSettingsUpdateConsumer` to only dynamic settings.

When I have time, I'll look at this some more, perhaps I'm mistaken. But my problem is solved. Thanks again.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 14, 2023, 3:32pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/6 "2023-04-14T15:32:05Z")

</div>

w00t! Thanks a lot @DavidTurner 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 12, 2023, 3:32pm UTC](https://discuss.elastic.co/t/configure-plugin-through-cluster-settings-api-listen-for-updates/329946/7 "2023-05-12T15:32:29Z")

</div>

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