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

Can not be registered in non web project

Open
#645 4 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

Describe the bug
I have a project providing gRPC service without any RestController. This project did't depend on spring-boot-starter-webflux nor spring-boot-starter-web. I found it could not be registered to the consul server.

It can be registered while using eureka as discovery client.


It is triggered in ConsulAutoServiceRegistrationListener

public void onApplicationEvent(ApplicationEvent applicationEvent) {
		if (applicationEvent instanceof WebServerInitializedEvent) {
			WebServerInitializedEvent event = (WebServerInitializedEvent) applicationEvent;

			ApplicationContext context = event.getApplicationContext();
			if (context instanceof ConfigurableWebServerApplicationContext) {
				if ("management"
						.equals(((ConfigurableWebServerApplicationContext) context)
								.getServerNamespace())) {
					return;
				}
			}
			this.autoServiceRegistration.setPortIfNeeded(event.getWebServer().getPort());
			this.autoServiceRegistration.start();
		}
	}

Then, how can I register it in non web project? Thanks!

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 with ConsulAutoServiceRegistrationListener and trace how registration is triggered by WebServerInitializedEvent. Compare the Consul path with the Eureka behavior for an application without a web server or REST controller. Done means a gRPC-only, non-web project can register with Consul without requiring spring-boot-starter-web or spring-boot-starter-webflux.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
distributed-systems
Issue type
Bug
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.