Skip to content

the bridge between different consul environment

Notifications You must be signed in to change notification settings

ns-cn/consul-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consul-bridge

consul-bridge: 架设多个consul环境之间的桥梁

Security Status

解决问题

  • 开发时需要本地开发调试,但本地服务又存在服务依赖问题
  • 本地配置不足以完整运行整套微服务
  • 需要接入其他环境做测试、debug等
  • 每次接入其他环境就需要更改大量的配置参数

实现方式

  • consul-bridge根据配置文件注册多个微服务实例到指定的consul(或本机的consul)
  • 通过本地监听端口实现对微服务请求做转发,接入其他测试环境

下载

手动安装

下载链接: windowslinuxmac

brew方式安装

brew tap ns-cn/ttools && brew install consul-bridge

go方式安装

# 安装最新版
go install github.com/ns-cn/consul-bridge@latest

使用

修改配置文件

设置转发规则yaml文件(默认是consul-bridge.yml)

consulAddress: 127.0.0.1:8500
agents:
  - { name: "baidu", "port": 8080, to: "www.baidu.com:80"}
  - { name: "micro-service-1", using: "http", "port": 10010, to: "remote-micro-service-1:10010"}
  - { name: "mysql", using: "tcp", "port": 3306, to: "remote-server:3306", ignore: true}
  - { name: "redis", using: "tcp", "port": 6379, to: "remote-server:6379", ignore: true}
  - { name: "rabbitmq", using: "tcp", "port": 5672, to: "remote-server:5672", ignore: true}
  - { name: "rabbitmq-ui", using: "http", "port": 15672, to: "remote-server:15672"}

其中

配置名 含义 值说明
consulAddress 本地consul地址
agents 转发规则, 可根据实际情况配置多组
name 注册到consul的服务名 如果忽略,则该值仅作显示用
using(可选) 端口监听方式 当前支持:http/tcp,默认http
ip(可选) 本地服务的Host,如需与局域网共同使用consul做服务联调,需修改该值 可选,默认为127.0.0.1
port 服务监听端口
to 目标转发地址
ignore 是否忽略(不注册到consul,默认false) 可选,默认值为false

启动

注: 可使用参数--load-l指定配置文件

# windows 使用默认文件(./consul_bridge.yml)加载
./consul_bridge.exe
# windows 指定配置文件加载
./consul_bridge.exe -l ./other_setting.yml
./consul_bridge.exe --load ./other_setting.yml


# linux 使用默认文件(./consul_bridge.yml)加载
./consul_bridge_linux
# windows 指定配置文件加载
./consul_bridge_linux -l ./other_setting.yml
./consul_bridge_linux --load ./other_setting.yml


# darwin 使用默认文件(./consul_bridge.yml)加载
./consul_bridge_darwin
# windows 指定配置文件加载
./onsul_bridge_darwin -l ./other_setting.yml
./onsul_bridge_darwin --load ./other_setting.yml

运行实例