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. 让UITableView的section header view不悬停的方法

    当 UITableView 的 style 属性设置为 Plain 时,这个tableview的section header在滚动时会默认悬停在界面顶端.取消这一特性的方法有两种: 将 style 设 ...

  2. python使用细节

    python的函数位置参数在调用时可以直接传参,也可以a=5,b=7的形式传参,原以为kw参数才可以. >>> def f(a,b): print a+b >>> ...

  3. tomcat 部署swagger 请求到后端乱码

    问题: @ApiOperation(value = "", notes = "查看关键词列表") @ResponseBody @RequestMapping(v ...

  4. js中子窗口调用父窗口中的变量、函数

  5. HTTPS数据传输过程简介

    HTTPS数据传输过程 1.客户端发起HTTPS连接握手 2.服务端收到HTTPS握手连接请求,与客户建立握手过程,和TCP的三次握手类似,并发送一系列的加密算法组合给客户端,与客户端协商加密算法组合 ...

  6. eclipse配置Servlet连接Mysql要注意的几个地方

    用Servlet即把jdbc那套放到继承于HttpServlet的派生类之内,那段代码很简单 protected void doPost(HttpServletRequest request, Htt ...

  7. 十字线阵---CBF,传统波束形成

    %传统波束形成,CBF (Ps:这个程序是别人的,不是我写的,但是具体是在哪里找到的已经忘了) clear all; close all; clc; %---------初始化常量---------- ...

  8. 浏览器DOM事件触发

    除用户人为交互触发事件外,用js脚本触发事件的一般流程为 创建事件 var e = Event('event_name', {key: value, ...}) 分发事件到 event.target ...

  9. [leetcode]98. Validate Binary Search Tree验证二叉搜索树

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  10. eclipse装了springboot插件后yml文件没有自动提示问题

    选择打开方式:spring yaml