Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul Admin Partition Support #813

Open
mmunar opened this issue Apr 10, 2023 · 0 comments
Open

Consul Admin Partition Support #813

mmunar opened this issue Apr 10, 2023 · 0 comments

Comments

@mmunar
Copy link

mmunar commented Apr 10, 2023

Describe the bug
Using spring-cloud-starter-consul-discovery version 3.1.2. Using a combination of Spring Boot microservice, Spring Cloud Consul plugins, Consul agents on Kubernetes, and Consul Enterprise with Admin Partitions. The microservices are able to register into the correct admin partition (as seen on Consul UI). However, when using DiscoveryClient, no microservices are able to be found. It appears it is only querying the default partition. Unable to find environment variable or Java API call to specify admin partition to query in.

pom.xml:

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-discovery</artifactId>
                <version>3.1.2</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-config</artifactId>
                <version>3.1.2</version>
            </dependency>

Sample code:

import org.springframework.cloud.client.discovery.DiscoveryClient;
...

@Component
public class AppDiscoveryClient {

    @Autowired
    private DiscoveryClient discoveryClient;

...

    private URI serviceUri(String serviceName) {
        List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
        if (instances == null || instances.isEmpty()) {
            throw new RuntimeException("Cannot find microservice " + serviceName);
        }
        ServiceInstance serviceInstance = instances.get(0);
        return serviceInstance.getUri();
    }

...

from logs:

Registering service with consul: NewService{id='api-10-0-0-147', name='api', tags=[contextPath=/api], address='10.0.0.147', meta={secure=false}, port=8080, enableTagOverride=null, check=Check{script='null', dockerContainerID='null', shell='null', interval='10s', ttl='null', http='http://10.0.0.147:8080/api/actuator/health', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null', grpc='null', grpcUseTLS=null}, checks=null}

When trying to query from another Spring boot microservice, there is the exception thrown of "Cannot find microservice api". When using the Consul REST API, the entries appear when adding partition as a query parameter to the GET services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants