Search in sources :

Example 1 with Subscriber

use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.

the class NamingSubscriberServiceV1ImplTest method testGetSubscribersWithServiceParam.

@Test
public void testGetSubscribersWithServiceParam() {
    Service service = Service.newService("1", "G1", "S1");
    Collection<Subscriber> actual = namingSubscriberService.getSubscribers(service);
    assertEquals(1, actual.size());
    assertSubscriber("1", "G1@@S1", actual.iterator().next());
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 2 with Subscriber

use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.

the class NamingSubscriberServiceV1ImplTest method testGetFuzzySubscribersWithServiceParam.

@Test
public void testGetFuzzySubscribersWithServiceParam() {
    Service service = Service.newService("1", "G", "S");
    Collection<Subscriber> actual = namingSubscriberService.getFuzzySubscribers(service);
    assertEquals(2, actual.size());
    assertSubscriber("1", "DEFAULT_GROUP@@S2", actual.iterator().next());
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 3 with Subscriber

use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.

the class InstanceController method list.

/**
 * Get all instance of input service.
 *
 * @param request http request
 * @return list of instance
 * @throws Exception any error during list
 */
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public Object list(HttpServletRequest request) throws Exception {
    String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
    String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
    NamingUtils.checkServiceNameFormat(serviceName);
    String agent = WebUtils.getUserAgent(request);
    String clusters = WebUtils.optional(request, "clusters", StringUtils.EMPTY);
    String clientIP = WebUtils.optional(request, "clientIP", StringUtils.EMPTY);
    int udpPort = Integer.parseInt(WebUtils.optional(request, "udpPort", "0"));
    boolean healthyOnly = Boolean.parseBoolean(WebUtils.optional(request, "healthyOnly", "false"));
    String app = WebUtils.optional(request, "app", StringUtils.EMPTY);
    Subscriber subscriber = new Subscriber(clientIP + ":" + udpPort, agent, app, clientIP, namespaceId, serviceName, udpPort, clusters);
    return getInstanceOperator().listInstance(namespaceId, serviceName, subscriber, clusters, healthyOnly);
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 4 with Subscriber

use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.

the class NamingSubscriberServiceV1Impl method getFuzzySubscribers.

@Override
public Collection<Subscriber> getFuzzySubscribers(String namespaceId, String serviceName) {
    Collection<Subscriber> result = new ArrayList<>();
    clientMap.forEach((outKey, clientConcurrentMap) -> {
        // get groupedName from key
        String serviceFullName = outKey.split(UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR)[1];
        // get groupName
        String groupName = NamingUtils.getGroupName(serviceFullName);
        // get serviceName
        String name = NamingUtils.getServiceName(serviceFullName);
        // fuzzy match
        if (outKey.startsWith(namespaceId) && name.indexOf(NamingUtils.getServiceName(serviceName)) >= 0 && groupName.indexOf(NamingUtils.getGroupName(serviceName)) >= 0) {
            clientConcurrentMap.forEach((key, client) -> {
                result.add(new Subscriber(client.getAddrStr(), client.getAgent(), client.getApp(), client.getIp(), namespaceId, serviceFullName, client.getPort()));
            });
        }
    });
    return result;
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) ArrayList(java.util.ArrayList)

Example 5 with Subscriber

use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.

the class SubscribeManagerTest method getSubscribersWithTrue.

@Test
public void getSubscribersWithTrue() {
    String serviceName = "testGroupName@@test_subscriber";
    String namespaceId = "public";
    boolean aggregation = Boolean.TRUE;
    try {
        List<Subscriber> clients = new ArrayList<>();
        Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, serviceName, 0);
        clients.add(subscriber);
        Mockito.when(this.aggregation.getFuzzySubscribers(Mockito.anyString(), Mockito.anyString())).thenReturn(clients);
        List<Subscriber> list = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
        Assert.assertNotNull(list);
        Assert.assertEquals(1, list.size());
        Assert.assertEquals("testGroupName@@test_subscriber", list.get(0).getServiceName());
        Assert.assertEquals("public", list.get(0).getNamespaceId());
    } catch (Exception ignored) {
    }
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Subscriber (com.alibaba.nacos.naming.pojo.Subscriber)15 Test (org.junit.Test)6 Secured (com.alibaba.nacos.auth.annotation.Secured)5 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)4 ArrayList (java.util.ArrayList)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)1 Member (com.alibaba.nacos.core.cluster.Member)1 Client (com.alibaba.nacos.naming.core.v2.client.Client)1 ClientManager (com.alibaba.nacos.naming.core.v2.client.manager.ClientManager)1 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)1 NoRequiredRetryException (com.alibaba.nacos.naming.push.v2.NoRequiredRetryException)1 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 LinkedList (java.util.LinkedList)1