Search in sources :

Example 1 with CoordinatorRegistryCenter

use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.

the class MqBeanInitRunner method run.

/**
 * Run.
 *
 * @param args the args
 */
@Override
public void run(String... args) throws Exception {
    CoordinatorRegistryCenter coordinatorRegistryCenter = RegistryCenterFactory.createCoordinatorRegistryCenter(paascloudProperties.getZk());
    List<String> childrenKeys = coordinatorRegistryCenter.getChildrenKeys(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH);
    this.initMqListener(coordinatorRegistryCenter);
    for (final String childrenKey : childrenKeys) {
        int count = coordinatorRegistryCenter.getNumChildren(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH + GlobalConstant.Symbol.SLASH + childrenKey);
        if (count == 0) {
            continue;
        }
        String producerString = coordinatorRegistryCenter.getDirectly(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH + GlobalConstant.Symbol.SLASH + childrenKey);
        ReliableMessageRegisterDto producerDto = JSON.parseObject(producerString, ReliableMessageRegisterDto.class);
        MqProducerBeanFactory.buildProducerBean(producerDto);
        try {
            tpcMqProducerService.updateOnLineStatusByPid(producerDto.getProducerGroup());
        } catch (Exception e) {
            log.error("更新生产者状态为离线出现异常, ex={}", e.getMessage(), e);
        }
    }
}
Also used : ReliableMessageRegisterDto(com.paascloud.core.registry.base.ReliableMessageRegisterDto) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Example 2 with CoordinatorRegistryCenter

use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.

the class RegistryCenterFactory method createCoordinatorRegistryCenter.

/**
 * 创建注册中心.
 *
 * @param zookeeperProperties the zookeeper properties
 *
 * @return 注册中心对象 coordinator registry center
 */
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(ZookeeperProperties zookeeperProperties) {
    Hasher hasher = Hashing.md5().newHasher().putString(zookeeperProperties.getZkAddressList(), Charsets.UTF_8);
    HashCode hashCode = hasher.hash();
    CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode);
    if (null != result) {
        return result;
    }
    result = new ZookeeperRegistryCenter(zookeeperProperties);
    result.init();
    REG_CENTER_REGISTRY.put(hashCode, result);
    return result;
}
Also used : ZookeeperRegistryCenter(com.paascloud.core.registry.zookeeper.ZookeeperRegistryCenter) Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Example 3 with CoordinatorRegistryCenter

use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.

the class IncrementIdGenerator method nextId.

/**
 * Next id long.
 *
 * @return the long
 */
@Override
public Long nextId() {
    String app = this.registerDto.getApp();
    String host = this.registerDto.getHost();
    CoordinatorRegistryCenter regCenter = this.registerDto.getCoordinatorRegistryCenter();
    String path = GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host;
    if (regCenter.isExisted(path)) {
        // 如果已经有该节点,表示已经为当前的host上部署的该app分配的编号(应对某个服务重启之后编号不变的问题),直接获取该id,而无需生成
        return Long.valueOf(regCenter.getDirectly(GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host));
    } else {
        // 节点不存在,那么需要生成id,利用zk节点的版本号每写一次就自增的机制来实现
        regCenter.increment(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3));
        // 生成id
        Integer id = regCenter.getAtomicValue(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3)).postValue();
        // 将数据写入节点
        regCenter.persist(path);
        regCenter.persist(path, String.valueOf(id));
        return Long.valueOf(id);
    }
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Example 4 with CoordinatorRegistryCenter

use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.

the class RegistryCenterFactory method registerMq.

private static void registerMq(PaascloudProperties paascloudProperties, String host, String app) {
    CoordinatorRegistryCenter coordinatorRegistryCenter = createCoordinatorRegistryCenter(paascloudProperties.getZk());
    AliyunProperties.RocketMqProperties rocketMq = paascloudProperties.getAliyun().getRocketMq();
    String consumerGroup = rocketMq.isReliableMessageConsumer() ? rocketMq.getConsumerGroup() : null;
    String namesrvAddr = rocketMq.getNamesrvAddr();
    String producerGroup = rocketMq.isReliableMessageProducer() ? rocketMq.getProducerGroup() : null;
    coordinatorRegistryCenter.registerMq(app, host, producerGroup, consumerGroup, namesrvAddr);
}
Also used : AliyunProperties(com.paascloud.config.properties.AliyunProperties) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Example 5 with CoordinatorRegistryCenter

use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.

the class RegistryCenterFactory method startup.

/**
 * Startup.
 *
 * @param paascloudProperties the paascloud properties
 * @param host                the host
 * @param app                 the app
 */
public static void startup(PaascloudProperties paascloudProperties, String host, String app) {
    CoordinatorRegistryCenter coordinatorRegistryCenter = createCoordinatorRegistryCenter(paascloudProperties.getZk());
    RegisterDto dto = new RegisterDto(app, host, coordinatorRegistryCenter);
    Long serviceId = new IncrementIdGenerator(dto).nextId();
    IncrementIdGenerator.setServiceId(serviceId);
    registerMq(paascloudProperties, host, app);
}
Also used : RegisterDto(com.paascloud.core.registry.base.RegisterDto) IncrementIdGenerator(com.paascloud.core.generator.IncrementIdGenerator) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Aggregations

CoordinatorRegistryCenter (com.paascloud.core.registry.base.CoordinatorRegistryCenter)5 HashCode (com.google.common.hash.HashCode)1 Hasher (com.google.common.hash.Hasher)1 AliyunProperties (com.paascloud.config.properties.AliyunProperties)1 IncrementIdGenerator (com.paascloud.core.generator.IncrementIdGenerator)1 RegisterDto (com.paascloud.core.registry.base.RegisterDto)1 ReliableMessageRegisterDto (com.paascloud.core.registry.base.ReliableMessageRegisterDto)1 ZookeeperRegistryCenter (com.paascloud.core.registry.zookeeper.ZookeeperRegistryCenter)1 RetryNTimes (org.apache.curator.retry.RetryNTimes)1