2.1 注册中心概述

2.1.1 一行代码的注册中心#

注册中心概述,支持服务变动钉钉通知。

using Anno.Rpc.Center;
using System;
namespace ViperCenter
{
class Program
{
/// <summary>
/// 注册中心只用增加一个 Anno.config配置文件,然后直接 Bootstrap.StartUp(args);启动即可
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.Title = "ViperCenter";
//服务变动钉钉通知
DingTalkNotify.CustomConfiguration.InitConst();
Bootstrap.StartUp(args
, (service, noticeType) =>//上线下线
{
DingTalkNotify.Notice(service,noticeType);
}, (newService, oldService) =>//服务配置更改
{
DingTalkNotify.ChangeNotice(newService, oldService);
});
}
}
}

2.1.2 配置文件#

配置文件 Anno.config

Port:为注册中心的监听端口
TimeOut:为注册中心默认连接超时时间单位毫秒
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--#lbs 配置-->
<Port>7010</Port>
<TimeOut>120000</TimeOut>
<Servers>
</Servers>
</configuration>

2.1.3 启动注册中心#

配置完成后便可以启动注册中心

Windows

dotnet ViperCenter.dll

Linux

#!/bin/bash
if [ $1 == "start" ];then
nohup dotnet ViperCenter.dll 2>&1 &
echo "$!" > pid
echo "start ok!"
elif [ $1 == "stop" ];then
kill `cat pid`
echo "stop ok!"
else
echo "Please make sure the position variable is start or stop."
fi

看到如下画面代表运行成功

此时可以去启动ViperService,注册ViperService 到注册中心