Search in sources :

Example 1 with ConfigChangeNotifyRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigChangeNotifyRequest in project nacos by alibaba.

the class RpcConfigChangeNotifier method configDataChanged.

/**
 * adaptor to config module ,when server side config change ,invoke this method.
 *
 * @param groupKey groupKey
 */
public void configDataChanged(String groupKey, String dataId, String group, String tenant, boolean isBeta, List<String> betaIps, String tag) {
    Set<String> listeners = configChangeListenContext.getListeners(groupKey);
    if (CollectionUtils.isEmpty(listeners)) {
        return;
    }
    int notifyClientCount = 0;
    for (final String client : listeners) {
        Connection connection = connectionManager.getConnection(client);
        if (connection == null) {
            continue;
        }
        ConnectionMeta metaInfo = connection.getMetaInfo();
        // beta ips check.
        String clientIp = metaInfo.getClientIp();
        String clientTag = metaInfo.getTag();
        if (isBeta && betaIps != null && !betaIps.contains(clientIp)) {
            continue;
        }
        // tag check
        if (StringUtils.isNotBlank(tag) && !tag.equals(clientTag)) {
            continue;
        }
        ConfigChangeNotifyRequest notifyRequest = ConfigChangeNotifyRequest.build(dataId, group, tenant);
        RpcPushTask rpcPushRetryTask = new RpcPushTask(notifyRequest, 50, client, clientIp, metaInfo.getAppName());
        push(rpcPushRetryTask);
        notifyClientCount++;
    }
    Loggers.REMOTE_PUSH.info("push [{}] clients ,groupKey=[{}]", notifyClientCount, groupKey);
}
Also used : Connection(com.alibaba.nacos.core.remote.Connection) ConnectionMeta(com.alibaba.nacos.core.remote.ConnectionMeta) ConfigChangeNotifyRequest(com.alibaba.nacos.api.config.remote.request.ConfigChangeNotifyRequest) TpsMonitorPoint(com.alibaba.nacos.core.remote.control.TpsMonitorPoint)

Example 2 with ConfigChangeNotifyRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigChangeNotifyRequest in project nacos by alibaba.

the class RpcConfigChangeNotifier method push.

private void push(RpcPushTask retryTask) {
    ConfigChangeNotifyRequest notifyRequest = retryTask.notifyRequest;
    if (retryTask.isOverTimes()) {
        Loggers.REMOTE_PUSH.warn("push callback retry fail over times .dataId={},group={},tenant={},clientId={},will unregister client.", notifyRequest.getDataId(), notifyRequest.getGroup(), notifyRequest.getTenant(), retryTask.connectionId);
        connectionManager.unregister(retryTask.connectionId);
    } else if (connectionManager.getConnection(retryTask.connectionId) != null) {
        // first time :delay 0s; sencond time:delay 2s  ;third time :delay 4s
        ConfigExecutor.getClientConfigNotifierServiceExecutor().schedule(retryTask, retryTask.tryTimes * 2, TimeUnit.SECONDS);
    } else {
    // client is already offline,ingnore task.
    }
}
Also used : ConfigChangeNotifyRequest(com.alibaba.nacos.api.config.remote.request.ConfigChangeNotifyRequest)

Aggregations

ConfigChangeNotifyRequest (com.alibaba.nacos.api.config.remote.request.ConfigChangeNotifyRequest)2 Connection (com.alibaba.nacos.core.remote.Connection)1 ConnectionMeta (com.alibaba.nacos.core.remote.ConnectionMeta)1 TpsMonitorPoint (com.alibaba.nacos.core.remote.control.TpsMonitorPoint)1