spring-cloud / spring-cloud/spring-cloud-consul

Event publisher after registration

Open
#758 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
822
Forks
539
Avg merge
9h 31m
Merged PRs (30d)
7

Description

Is your feature request related to a problem? Please describe.
I want to run specific logic after an application register itself in a Consul service registry. I'm implementing an app-level leader election based on the Consul as described in tutorial: https://learn.hashicorp.com/tutorials/consul/application-leader-elections . It would be nice to have dedicated event publisher with a result of Consul registration,

Describe the solution you'd like

public class LeaderElector implements ApplicationListener<ConsulRegistrationCompleted> {
//...
  public void onApplicationEvent(ConsulRegistrationCompleted event){
  //do election
  }
}

Describe alternatives you've considered
Currently, I trigger election using

public class LeaderElector implements CommandLineRunner {
//...
}

Alternatively, above could be implemented using ApplicationListener<ApplicationStartedEvent>.

Additional context
Above solutions don't give any state of an application's registration and it must be retrieved manually before starting actual logic. Also, using standard event is fragile when Consul's integration is disabled in configuration (e.g. spring.cloud.consul.enabled=false) - implementation become complicated with non-null checks against Consul-related beans. Dedicated event could simplified this case, because it never occur when consul registration is disabled.

Let me know what you think.
Cheers!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Consul registration lifecycle and comparing it with ApplicationStartedEvent and CommandLineRunner. Define what ConsulRegistrationCompleted should expose, ensure it is emitted only after registration succeeds and is absent when Consul registration is disabled, then verify the event can be consumed through ApplicationListener.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.