Skip to content

io microsphere spring cloud client discovery UnionDiscoveryClient

github-actions[bot] edited this page Mar 26, 2026 · 3 revisions

UnionDiscoveryClient

Type: Class | Module: microsphere-spring-cloud-commons | Package: io.microsphere.spring.cloud.client.discovery | Since: 1.0.0

Source: microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/discovery/UnionDiscoveryClient.java

Overview

The DiscoveryClient implementation for a union of the given DiscoveryClient

Declaration

public final class UnionDiscoveryClient implements DiscoveryClient, ApplicationContextAware, SmartInitializingSingleton, DisposableBean

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.5-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getDiscoveryClients

UnionDiscoveryClient unionClient = applicationContext.getBean(UnionDiscoveryClient.class);
List<DiscoveryClient> clients = unionClient.getDiscoveryClients();
clients.forEach(c -> System.out.println(c.description()));

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-cloud-commons</artifactId>
    <version>${microsphere-spring-cloud.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-cloud-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.cloud.client.discovery.UnionDiscoveryClient;

API Reference

Public Methods

Method Description
description {@inheritDoc}
getInstances {@inheritDoc}
getServices {@inheritDoc}
getDiscoveryClients Returns the sorted list of underlying DiscoveryClient DiscoveryClients, excluding
getOrder {@inheritDoc}
afterSingletonsInstantiated {@inheritDoc}
destroy {@inheritDoc}
setApplicationContext {@inheritDoc}

Method Details

getInstances

public List<ServiceInstance> getInstances(String serviceId)

{@inheritDoc}

Aggregates service instances from all underlying DiscoveryClient DiscoveryClients.

getServices

public List<String> getServices()

{@inheritDoc}

Returns a deduplicated union of service names from all underlying DiscoveryClient DiscoveryClients.

getDiscoveryClients

public List<DiscoveryClient> getDiscoveryClients()

Returns the sorted list of underlying DiscoveryClient DiscoveryClients, excluding CompositeDiscoveryClient and this instance itself. The list is lazily initialized from the ApplicationContext on first access and cached for subsequent calls.

Example Usage:

`UnionDiscoveryClient unionClient = applicationContext.getBean(UnionDiscoveryClient.class);
List clients = unionClient.getDiscoveryClients();
clients.forEach(c -> System.out.println(c.description()));
`

afterSingletonsInstantiated

public void afterSingletonsInstantiated()

{@inheritDoc}

Eagerly initializes the list of DiscoveryClient DiscoveryClients after all singletons are instantiated.

destroy

public void destroy()

{@inheritDoc}

Clears the cached list of DiscoveryClient DiscoveryClients on bean destruction.

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)

{@inheritDoc}

Stores the ApplicationContext used to look up DiscoveryClient beans.

See Also

  • CompositeDiscoveryClient

This documentation was auto-generated from the source code of microsphere-spring-cloud.

Home

spring-cloud-commons

spring-cloud-openfeign

Clone this wiki locally