Skip to content

Commit

Permalink
[ISSUE #1097] Naming support un/subscribe service by grpc. (#3373)
Browse files Browse the repository at this point in the history
* For #1097, server support subscribe service.

* For #1097, client support subscribe service.

* For #1097, server and client support unsubscribe service.
  • Loading branch information
KomachiSion authored Jul 18, 2020
1 parent 4a702f8 commit 3bde282
Show file tree
Hide file tree
Showing 24 changed files with 790 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public class NamingRemoteConstants {

public static final String DE_REGISTER_INSTANCE = "deregisterInstance";

public static final String SUBSCRIBE_SERVICE = "subscribeService";

public static final String QUERY_SERVICE = "queryService";

public static final String SUBSCRIBE_SERVICE = "subscribeService";

public static final String NOTIFY_SUBSCRIBER = "notifySubscriber";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public class InstanceRequest extends NamingCommonRequest {
public InstanceRequest() {
}

public InstanceRequest(String namespace, String serviceName, String type, Instance instance) {
super(namespace, serviceName, null);
this.type = type;
this.instance = instance;
}

public InstanceRequest(String namespace, String serviceName, String groupName, String type, Instance instance) {
super(namespace, serviceName, groupName);
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.naming.remote.request;

import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;

/**
* Nacos naming subscribe service request.
*
* @author xiweng.yy
*/
public class SubscribeServiceRequest extends NamingCommonRequest {

private boolean subscribe;

private String clusters;

public SubscribeServiceRequest() {
}

public SubscribeServiceRequest(String namespace, String serviceName, String clusters, boolean subscribe) {
super(namespace, serviceName, null);
this.clusters = clusters;
this.subscribe = subscribe;
}

@Override
public String getType() {
return NamingRemoteConstants.SUBSCRIBE_SERVICE;
}

public String getClusters() {
return clusters;
}

public void setClusters(String clusters) {
this.clusters = clusters;
}

public boolean isSubscribe() {
return subscribe;
}

public void setSubscribe(boolean subscribe) {
this.subscribe = subscribe;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ public class InstanceResponse extends Response {
public InstanceResponse() {
}

@Override
public String getType() {
return this.type;
public InstanceResponse(String type) {
this.type = type;
}

public InstanceResponse(String type) {
public void setType(String type) {
this.type = type;
}

@Override
public String getType() {
return this.type;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.naming.remote.response;

import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode;

/**
* Notify subscriber response.
*
* @author xiweng.yy
*/
public class NotifySubscriberResponse extends Response {

private ServiceInfo serviceInfo;

public NotifySubscriberResponse() {
}

private NotifySubscriberResponse(ServiceInfo serviceInfo, String message) {
this.serviceInfo = serviceInfo;
setMessage(message);
}

public static NotifySubscriberResponse buildSuccessResponse(ServiceInfo serviceInfo) {
return new NotifySubscriberResponse(serviceInfo, "success");
}

/**
* Build fail response.
*
* @param message error message
* @return faile response
*/
public static NotifySubscriberResponse buildFailResponse(String message) {
NotifySubscriberResponse result = new NotifySubscriberResponse();
result.setErrorCode(ResponseCode.FAIL.getCode());
result.setMessage(message);
return result;
}

@Override
public String getType() {
return NamingRemoteConstants.NOTIFY_SUBSCRIBER;
}

public ServiceInfo getServiceInfo() {
return serviceInfo;
}

public void setServiceInfo(ServiceInfo serviceInfo) {
this.serviceInfo = serviceInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,43 @@
*
* @author xiweng.yy
*/
public class ServiceQueryResponse extends Response {
public class QueryServiceResponse extends Response {

private ServiceInfo serviceInfo;

public ServiceQueryResponse() {
public QueryServiceResponse() {
}

@Override
public String getType() {
return NamingRemoteConstants.QUERY_SERVICE;
}

public ServiceQueryResponse(ServiceInfo serviceInfo) {
private QueryServiceResponse(ServiceInfo serviceInfo) {
this.serviceInfo = serviceInfo;
}

public static ServiceQueryResponse buildSuccessResponse(ServiceInfo serviceInfo) {
ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse();
serviceQueryResponse.setServiceInfo(serviceInfo);
return serviceQueryResponse;
/**
* Build Success response.
*
* @param serviceInfo service info
* @return service query response
*/
public static QueryServiceResponse buildSuccessResponse(ServiceInfo serviceInfo) {
return new QueryServiceResponse(serviceInfo);
}

public static ServiceQueryResponse buildFailResponse(String message) {
ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse();
serviceQueryResponse.setResultCode(ResponseCode.FAIL.getCode());
serviceQueryResponse.setMessage(message);
return serviceQueryResponse;
/**
* Build fail response.
*
* @param message message
* @return service query response
*/
public static QueryServiceResponse buildFailResponse(String message) {
QueryServiceResponse queryServiceResponse = new QueryServiceResponse();
queryServiceResponse.setResultCode(ResponseCode.FAIL.getCode());
queryServiceResponse.setMessage(message);
return queryServiceResponse;
}

public ServiceInfo getServiceInfo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.naming.remote.response;

import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.alibaba.nacos.api.remote.response.Response;

/**
* Nacos naming subscribe service response.
*
* @author xiweng.yy
*/
public class SubscribeServiceResponse extends Response {

private ServiceInfo serviceInfo;

public SubscribeServiceResponse() {
}

public SubscribeServiceResponse(int resultCode, String message, ServiceInfo serviceInfo) {
super();
setResultCode(resultCode);
setMessage(message);
this.serviceInfo = serviceInfo;
}

@Override
public String getType() {
return NamingRemoteConstants.SUBSCRIBE_SERVICE;
}

public ServiceInfo getServiceInfo() {
return serviceInfo;
}

public void setServiceInfo(ServiceInfo serviceInfo) {
this.serviceInfo = serviceInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import com.alibaba.nacos.api.config.remote.response.ConfigResponseTypeConstants;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.alibaba.nacos.api.naming.remote.response.InstanceResponse;
import com.alibaba.nacos.api.naming.remote.response.ServiceQueryResponse;
import com.alibaba.nacos.api.naming.remote.response.NotifySubscriberResponse;
import com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse;
import com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse;
import com.alibaba.nacos.api.remote.response.ConnectResetResponse;
import com.alibaba.nacos.api.remote.response.HeartBeatResponse;
import com.alibaba.nacos.api.remote.response.ResponseTypeConstants;
Expand Down Expand Up @@ -60,7 +62,9 @@ public class ResponseRegistry {
//naming response registry
REGISTRY_RESPONSES.put(NamingRemoteConstants.REGISTER_INSTANCE, InstanceResponse.class);
REGISTRY_RESPONSES.put(NamingRemoteConstants.DE_REGISTER_INSTANCE, InstanceResponse.class);
REGISTRY_RESPONSES.put(NamingRemoteConstants.QUERY_SERVICE, ServiceQueryResponse.class);
REGISTRY_RESPONSES.put(NamingRemoteConstants.QUERY_SERVICE, QueryServiceResponse.class);
REGISTRY_RESPONSES.put(NamingRemoteConstants.SUBSCRIBE_SERVICE, SubscribeServiceResponse.class);
REGISTRY_RESPONSES.put(NamingRemoteConstants.NOTIFY_SUBSCRIBER, NotifySubscriberResponse.class);
}

public static Class getClassByType(String type) {
Expand Down
Loading

0 comments on commit 3bde282

Please sign in to comment.