using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Consul; namespace consulTest
{
class Program
{
static void Main(string[] args)
{
//注册Consul
string ip = "127.0.0.1";
string port = "";
string serviceName = "MsgService";
string serviceId = serviceName + Guid.NewGuid(); using (var consulClient = new ConsulClient(ConsulConfig))
{
var agentServer = new AgentServiceRegistration
{
Address = ip,
Port = Convert.ToInt32(port),
ID = serviceId,
Name = serviceName,
Check = new AgentServiceCheck
{
DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(),
HTTP = $"http://www.baidu.com",
Interval = TimeSpan.FromSeconds(),
Timeout = TimeSpan.FromSeconds(),
},
}; consulClient.Agent.ServiceRegister(agentServer).Wait();
Console.WriteLine("服务注册成功"); var serverDic = consulClient.Agent.Services().Result.Response;
foreach (var s in serverDic.Values)
{
Console.WriteLine($"ID={s.ID},Service={s.Service},Addr={s.Address},Port={s.Port}");
}
Console.ReadLine();
}
} //Consul 配置委托
private static void ConsulConfig(ConsulClientConfiguration config)
{
config.Address = new Uri("http://127.0.0.1:8500"); //Demo硬编码Consul的地址
config.Datacenter = "dc1";
}
}
}

consul服务注册与发现的更多相关文章

  1. 微服务~Consul服务注册与发现

    服务发现是基于微服务架构的关键原则之一.尝试配置每个客户端或某种形式的约定可能非常困难,可以非常脆弱.Consul通过HTTP API和DNS提供服务发现服务.Spring Cloud Consul利 ...

  2. SpringBoot + Spring Cloud Consul 服务注册和发现

    什么是Consul Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其它分布式服务注册与发现的方案,Consul 的方案更"一站式" ...

  3. (8)ASP.NET Core3.1 Ocelot Consul服务注册与发现

    1.服务注册与发现(Service Discovery) ●服务注册:我们通过在每个服务实例写入注册代码,实例在启动的时候会先去注册中心(例如Consul.ZooKeeper.etcd.Eureka) ...

  4. 温故知新,.Net Core遇见Consul(HashiCorp),实践分布式服务注册与发现

    什么是Consul 参考 https://www.consul.io https://www.hashicorp.com 使用Consul做服务发现的若干姿势 ASP.NET Core 发布之后通过命 ...

  5. 三. SpringCloud服务注册与发现

    1. Eureka 1.1 Eureka理解 什么是服务治理 Spring Cloud封装了Netflix公司开发的Eurkeka模块来实现服务治理 在传统的rpc远程调用框架中,管理每个服务与服务之 ...

  6. Consul 服务注册与服务发现

    上一篇:Mac OS.Ubuntu 安装及使用 Consul 1. 服务注册 对 Consul 进行服务注册之前,需要先部署一个服务站点,我们可以使用 ASP.NET Core 创建 Web 应用程序 ...

  7. 分布式服务注册和发现consul 简要介绍

    Consul是HashiCorp公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发现的方案,Consul的方案更"一站式",内置了服务注册与发现框 架 ...

  8. SpringCloud+Consul 服务注册与服务发现

    SpringCloud+Consul 服务注册与服务发现 1. 服务注册: 在Spring.factories有一段: # Discovery Client Configuration org.spr ...

  9. Spring Cloud Consul 实现服务注册和发现

    Spring Cloud 是一个基于 Spring Boot 实现的云应用开发工具,它为基于 JVM 的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布 ...

随机推荐

  1. 先 FROM 后 WHERE 再 GROUP BY 再 SELECT 再 order BY

    shutdown -r -t 5office:515740906family-asus:786512915office-T420i:837829568 family-T420:868 638 325 ...

  2. spark java.lang.OutOfMemoryError: unable to create new native thread

    最近迁移集群,在hadoop-2.8.4 的yarn上跑 spark 程序 报了以下错误 java.lang.OutOfMemoryError: unable to create new native ...

  3. leetcode3

    public class Solution { public int LengthOfLongestSubstring(string s) { var dic = new Dictionary< ...

  4. html网页练习豆瓣网

    html </head> <body>     <!-- 头部 -->     <header class="header1">   ...

  5. 看到blackarch 字体不错 记录下来

    terminus-font

  6. jenkins+sonarQube代码质量扫描 并排除指定的目录

    sonar.projectKey=dev1-news-paymentsonar.projectName=dev1-news-paymentsonar.projectVersion=$BUILD_NUM ...

  7. 10. Regular Expression Matching (JAVA)

    Given an input string (s) and a pattern (p), implement regular expression matching with support for ...

  8. Git 基础 - 删除暂存区的文件

    1 直接删除文件 这个文件会有两个操作:已暂存的修改.未暂存的删除 2 直接删除文件 + 记录删除操作 先在工作目录中删除文件,再使用git rm命令记录此次移除文件的操作(删除暂存区中该文件的修改快 ...

  9. thinkphp5中使用excel导出数据表格(包涵图片)

    首先使用composer require phpoffice/phpexcel下载安装phpexcel包. 将包放入extend下面. 不附加图片的导出 /** * 导出excel(不带图片) * @ ...

  10. 手机连得上WIFI,电脑连不上的情况

    可以搜到,密码也对,但就是连不上,这时候可能就是你的设置错了. 操作步骤以下: 右击我的电脑-->管理-->设备管理器-->网络适配器-->找到你wifi对应的那个名称(如果不 ...