Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
[#40]存在 autowire 的场景, 会将 consumer 注册为 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Oct 16, 2020
1 parent 9addf76 commit ce8c247
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import com.huaweicloud.dubbo.common.SchemaInfo;

public class RegistrationListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware {
private static final String PROTOCOL_CONSUMER = "consumer";

static class SubscriptionKey {
final String appId;

Expand Down Expand Up @@ -178,7 +180,10 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
instance = ServiceCenterConfiguration.createMicroserviceInstance();
List<String> endpoints = new ArrayList<>();
if (registry != null) {
endpoints.addAll(registry.getRegisters().stream().map(URL::toString).collect(Collectors.toList()));
endpoints.addAll(registry.getRegisters().stream()
.filter(item -> !item.getProtocol().equals(PROTOCOL_CONSUMER))
.map(URL::toString)
.collect(Collectors.toList()));
}
instance.setEndpoints(endpoints);
instance.setHostName(InetAddress.getLocalHost().getHostName());
Expand All @@ -197,7 +202,7 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
} else if (applicationEvent instanceof NewSubscriberEvent) {
NewSubscriberEvent newSubscriberEvent = (NewSubscriberEvent) applicationEvent;
// 第一次订阅, 按照 dubbo 的要求, 需要查询实例列表
if (newSubscriberEvent.getUrl().getProtocol().equals("consumer")) {
if (newSubscriberEvent.getUrl().getProtocol().equals(PROTOCOL_CONSUMER)) {
if (registrationInProgress) {
pendingSubscribeEvent.add(newSubscriberEvent);
return;
Expand Down

0 comments on commit ce8c247

Please sign in to comment.