Skip to content

Commit 336c90e

Browse files
authored
Merge pull request #80 from mercyblitz/dev-1.x
Release 0.1.3
2 parents 395cfd3 + 21e4f1c commit 336c90e

File tree

41 files changed

+690
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+690
-62
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pom.xml:
6262

6363
| **Branches** | **Purpose** | **Latest Version** |
6464
|--------------|--------------------------------------------------|--------------------|
65-
| **0.2.x** | Compatible with Spring Cloud 2022.0.x - 2025.0.x | 0.2.1 |
66-
| **0.1.x** | Compatible with Spring Cloud Hoxton - 2021.0.x | 0.1.1 |
65+
| **0.2.x** | Compatible with Spring Cloud 2022.0.x - 2025.0.x | 0.2.3 |
66+
| **0.1.x** | Compatible with Spring Cloud Hoxton - 2021.0.x | 0.1.3 |
6767

6868
Then add the specific modules you need:
6969

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.spring.cloud.client.discovery;
19+
20+
import org.springframework.cloud.client.ServiceInstance;
21+
import org.springframework.cloud.client.discovery.DiscoveryClient;
22+
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
23+
import reactor.core.publisher.Flux;
24+
25+
import java.util.List;
26+
27+
/**
28+
* An adapter {@link DiscoveryClient} class based on {@link ReactiveDiscoveryClient}
29+
*
30+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
31+
* @see DiscoveryClient
32+
* @since 1.0.0
33+
*/
34+
public class ReactiveDiscoveryClientAdapter implements DiscoveryClient {
35+
36+
private final ReactiveDiscoveryClient reactiveDiscoveryClient;
37+
38+
public ReactiveDiscoveryClientAdapter(ReactiveDiscoveryClient reactiveDiscoveryClient) {
39+
this.reactiveDiscoveryClient = reactiveDiscoveryClient;
40+
}
41+
42+
@Override
43+
public String description() {
44+
return this.reactiveDiscoveryClient.description();
45+
}
46+
47+
@Override
48+
public List<ServiceInstance> getInstances(String serviceId) {
49+
Flux<ServiceInstance> flux = this.reactiveDiscoveryClient.getInstances(serviceId);
50+
return toList(flux);
51+
}
52+
53+
@Override
54+
public List<String> getServices() {
55+
Flux<String> flux = this.reactiveDiscoveryClient.getServices();
56+
return toList(flux);
57+
}
58+
59+
@Override
60+
public void probe() {
61+
this.reactiveDiscoveryClient.probe();
62+
}
63+
64+
@Override
65+
public int getOrder() {
66+
return this.reactiveDiscoveryClient.getOrder();
67+
}
68+
69+
static <T> List<T> toList(Flux<T> flux) {
70+
return flux.collectList().block();
71+
}
72+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/discovery/autoconfigure/DiscoveryClientAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ public UnionDiscoveryClient unionDiscoveryClient() {
8585
return new UnionDiscoveryClient();
8686
}
8787
}
88-
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.spring.cloud.client.discovery.autoconfigure;
19+
20+
import io.microsphere.spring.cloud.client.discovery.ReactiveDiscoveryClientAdapter;
21+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24+
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
25+
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
26+
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
27+
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.context.annotation.Configuration;
30+
31+
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.DISCOVERY_CLIENT_CLASS_NAME;
32+
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.REACTIVE_COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
33+
34+
/**
35+
* The Auto-Configuration class for {@link ReactiveDiscoveryClient}
36+
*
37+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
38+
* @see ReactiveDiscoveryClient
39+
* @see DiscoveryClientAutoConfiguration
40+
* @since 1.0.0
41+
*/
42+
@Configuration(proxyBeanMethods = false)
43+
@ConditionalOnClass(name = {
44+
DISCOVERY_CLIENT_CLASS_NAME
45+
})
46+
@ConditionalOnDiscoveryEnabled
47+
@ConditionalOnReactiveDiscoveryEnabled
48+
@AutoConfigureBefore(name = {
49+
REACTIVE_COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME
50+
})
51+
public class ReactiveDiscoveryClientAutoConfiguration {
52+
53+
@Configuration(proxyBeanMethods = false)
54+
@ConditionalOnBlockingDiscoveryEnabled
55+
public static class BlockingConfiguration {
56+
57+
@Bean
58+
@ConditionalOnBean(ReactiveDiscoveryClient.class)
59+
public ReactiveDiscoveryClientAdapter reactiveDiscoveryClientAdapter(ReactiveDiscoveryClient reactiveDiscoveryClient) {
60+
return new ReactiveDiscoveryClientAdapter(reactiveDiscoveryClient);
61+
}
62+
}
63+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/discovery/constants/DiscoveryClientConstants.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.microsphere.spring.cloud.client.discovery.constants;
1818

1919
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
20+
import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration;
2021
import org.springframework.cloud.client.discovery.DiscoveryClient;
2122
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
2223

@@ -30,17 +31,29 @@ public interface DiscoveryClientConstants {
3031

3132
/**
3233
* The class name of {@link DiscoveryClient}
34+
*
35+
* @see org.springframework.cloud.client.discovery.DiscoveryClient
3336
*/
3437
String DISCOVERY_CLIENT_CLASS_NAME = "org.springframework.cloud.client.discovery.DiscoveryClient";
3538

3639
/**
3740
* The class name of {@link CompositeDiscoveryClient}
41+
*
42+
* @see org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient
3843
*/
3944
String COMPOSITE_DISCOVERY_CLIENT_CLASS_NAME = "org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient";
4045

4146
/**
4247
* The class name of {@link CommonsClientAutoConfiguration}
48+
*
49+
* @see org.springframework.cloud.client.CommonsClientAutoConfiguration
4350
*/
4451
String COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.client.CommonsClientAutoConfiguration";
4552

46-
}
53+
/**
54+
* The class name of {@link ReactiveCommonsClientAutoConfiguration}
55+
*
56+
* @see org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration
57+
*/
58+
String REACTIVE_COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration";
59+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ public boolean isProcessed() {
8686
return processed;
8787
}
8888

89-
}
89+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/DefaultRegistration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
* @since 1.0.0
2828
*/
2929
public class DefaultRegistration extends DefaultServiceInstance implements Registration {
30-
}
30+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/InMemoryServiceRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ protected Map<String, String> getMetadata(Registration registration) {
7777
}
7878
return null;
7979
}
80-
}
80+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/MultipleAutoServiceRegistration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ protected MultipleRegistration getRegistration() {
4747
protected MultipleRegistration getManagementRegistration() {
4848
return this.multipleRegistration;
4949
}
50-
}
50+
}

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/MultipleRegistration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ public <T extends Registration> T special(Class<T> specialClass) {
8585
return (T) this;
8686
return (T) this.registrationMap.getOrDefault(specialClass, null);
8787
}
88-
}
88+
}

0 commit comments

Comments
 (0)