use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class SubscribeServiceRequestHandler method handle.
@Override
@Secured(action = ActionTypes.READ)
public SubscribeServiceResponse handle(SubscribeServiceRequest request, RequestMeta meta) throws NacosException {
String namespaceId = request.getNamespace();
String serviceName = request.getServiceName();
String groupName = request.getGroupName();
String app = request.getHeader("app", "unknown");
String groupedServiceName = NamingUtils.getGroupedName(serviceName, groupName);
Service service = Service.newService(namespaceId, groupName, serviceName, true);
Subscriber subscriber = new Subscriber(meta.getClientIp(), meta.getClientVersion(), app, meta.getClientIp(), namespaceId, groupedServiceName, 0, request.getClusters());
ServiceInfo serviceInfo = ServiceUtil.selectInstancesWithHealthyProtection(serviceStorage.getData(service), metadataManager.getServiceMetadata(service).orElse(null), subscriber);
if (request.isSubscribe()) {
clientOperationService.subscribeService(service, subscriber, meta.getConnectionId());
} else {
clientOperationService.unsubscribeService(service, subscriber, meta.getConnectionId());
}
return new SubscribeServiceResponse(ResponseCode.SUCCESS.getCode(), "success", serviceInfo);
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testListInstance.
@Test
public void testListInstance() {
Mockito.when(pushService.canEnablePush(Mockito.anyString())).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("DEFAULT_GROUP");
serviceInfo.setName("B");
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata metadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
Subscriber subscriber = new Subscriber("2.2.2.2", "", "app", "1.1.1.1", "A", "B", 8848);
instanceOperatorClient.listInstance("A", "B", subscriber, "C", true);
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class PushExecuteTask method run.
@Override
public void run() {
try {
PushDataWrapper wrapper = generatePushData();
ClientManager clientManager = delayTaskEngine.getClientManager();
for (String each : getTargetClientIds()) {
Client client = clientManager.getClient(each);
if (null == client) {
// means this client has disconnect
continue;
}
Subscriber subscriber = clientManager.getClient(each).getSubscriber(service);
delayTaskEngine.getPushExecutor().doPushWithCallback(each, subscriber, wrapper, new NamingPushCallback(each, subscriber, wrapper.getOriginalData(), delayTask.isPushToAll()));
}
} catch (Exception e) {
Loggers.PUSH.error("Push task for service" + service.getGroupedServiceName() + " execute failed ", e);
delayTaskEngine.addTask(service, new PushDelayTask(service, 1000L));
}
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class InstanceControllerV2 method list.
/**
* Get all instance of input service.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param clusters service clusters
* @param clientIP service clientIP
* @param udpPort udpPort
* @param healthyOnly healthyOnly
* @param app app
* @param request http request
* @return list of instance
* @throws Exception any error during list
*/
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public Object list(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam(defaultValue = StringUtils.EMPTY) String clusters, @RequestParam(defaultValue = StringUtils.EMPTY) String clientIP, @RequestParam(defaultValue = "0") Integer udpPort, @RequestParam(defaultValue = "false") Boolean healthyOnly, @RequestParam(defaultValue = StringUtils.EMPTY) String app, HttpServletRequest request) throws Exception {
NamingUtils.checkServiceNameFormat(serviceName);
String agent = WebUtils.getUserAgent(request);
Subscriber subscriber = new Subscriber(clientIP + ":" + udpPort, agent, app, clientIP, namespaceId, serviceName, udpPort, clusters);
return instanceServiceV2.listInstance(namespaceId, serviceName, subscriber, clusters, healthyOnly);
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class NamingSubscriberServiceV2ImplTest method setUp.
@Before
public void setUp() throws Exception {
subscriberService = new NamingSubscriberServiceV2Impl(clientManager, indexesManager, null, null, null, upgradeJudgement, switchDomain);
ReflectionTestUtils.setField(subscriberService, "delayTaskEngine", delayTaskEngine);
when(indexesManager.getAllClientsSubscribeService(service)).thenReturn(Collections.singletonList(testClientId));
when(indexesManager.getAllClientsSubscribeService(service1)).thenReturn(Collections.singletonList(testClientId));
Collection<Service> services = new LinkedList<>();
services.add(service);
services.add(service1);
when(indexesManager.getSubscribedService()).thenReturn(services);
when(clientManager.getClient(testClientId)).thenReturn(client);
when(client.getSubscriber(service)).thenReturn(new Subscriber("1.1.1.1:1111", "Test", "unknown", "1.1.1.1", "N", service.getGroupedServiceName(), 0));
when(client.getSubscriber(service1)).thenReturn(new Subscriber("1.1.1.1:1111", "Test", "unknown", "1.1.1.1", "N", service1.getGroupedServiceName(), 0));
when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true);
}
Aggregations