1.3.3 • Published 7 years ago

cms-public v1.3.3

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

cms-public

benditoutiao cms public module:

Installation

npm install cms-public

Usage

TOC

MongoServices

####连接mongodb

MongoServices.connectMongodb(MongoServiceParas);

Arguments MongoServiceParas Array

####使用

const hd = MongoServices.mongoHds[instanceName];
let news = hd.model(collectionName, NewsSchema);

###RedisServices:

####连接redis

RedisServices.connectRedis(redisServiceParas);

Arguments

redisServiceParas Array ####使用

const redisClient = RedisServices.redisHds[instanceName];
redisClient.set(redisKey,JSON.stringify(cacheData));
redisClient.set(redisKey,JSON.stringify(cacheData),'EX',expire);
redisClient.get(redisKey,function(err,result){
    if (err) {
        monitor.error(`redisClient get data error`);
    }
});
redisClient.del(redisKey,function(err){
    if (err) {
        monitor.error(`redisClient del error`);

    }else{
        resolve(`redisClient del success , key : ${redisKey}`);
    }
})

SequelizeServices

####连接Mysql

SequelizeServices.initSequelize(sequelizeServiceParas);

Arguments

sequelizeServiceParas Array

####定义model

const db = SequelizeServices.sequelizeHds.source;
const Bbs = db.defineModel('bbs','bbs_subscribe_nexus', {
    bbs_id:db.BIGINT(20),
    site_id:{
        type:db.INTEGER(11),
        allowNull:false
    }
});

const Bbs = db.define('bbs_subscribe_nexus', {
    bbs_id:db.BIGINT(20),
    site_id:{
        type:db.INTEGER(11),
        allowNull:false
    }
});

####使用model

Bbs.localNewsSortModel.findAll({
        where:{
            news_id:id,
            is_delete:0
        }
    });

OssService

连接OSS

OssService.initOSSClient(ossServerPara);

Arguments

ossServerPara Object

GrpcService

####连接 Grpc Server

GrpcService.initServiceApi({
    PROTO_PATH:PROTO_PATH,
    port:argument.rpcPort,
    serviceName:'getNews',
    interface:require('./proto/newsGrpcInterface')
});

Arguments

PROTO_PATH proto文件路径 port rpc服务端口 serviceName proto 定义的服务名 interface rpc 服务的接口 ####调用方法 GrpcService.client'getNews'.getAllShowType()

KafkaService

####创建kafka消费者

KafkaService.createConsumer({address:'localhost:2181',topics:[{
topic: 'cms',
partition:0
}]},callback);

Arguments

address kafka服务ip , port topics Array 消费者订阅 topic partition

####创建生产者

KafkaService.createProducer({address:'127.0.0.1:2181'});

####发布消息

KafkaService.sendMsg([{
    topic: 'cms',
    messages: JSON.stringify({operation:'onlineStatusSync',data:{
        online_news_id:74277294,
        status:0
    }})
}], function(err, result) {
    console.log(err || result);
});

###LoadBalancer

####Grpc负载均衡

 RpcLoadBalancer.init([{
    ip:'0.0.0.0:50051',
    PROTO_PATH:PROTO_PATH,
    serviceName:'getNews'
}]);

####调用方法

RpcLoadBalancer.selectChannel('getNews').getOnlineData()
1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago