gRPC服务发现与服务治理,目前常见解决方案有以下两种
本文粗略讲解一下两种方案的优缺点
nginx-consul.conf大致如下
# nginx需要安装grpc模块
upstream User {
server 127.0.0.1:17000;
server 127.0.0.1:18000;
}
server {
listen 19000 http2;
server_name _;
location /protobuf.User {
default_type application/grpc;
grpc_pass grpc://User;
}
}
复制代码
Envoy 是专为大型现代 SOA(面向服务架构)架构设计的 L7 代理和通信总线。是istio重要组件之一
不好意思 ,没图, 直接贴envoy.yaml出来讲解一下
node:
id: id_1
cluster: test_cluster
watchdog:
miss_timeout: 0.2s
megamiss_timeout: 1s
kill_timeout: 0s
multikill_timeout: 0s
admin:
access_log_path: /var/log/admin_access.log
address:
socket_address: { address: 127.0.0.1, port_value: 10000 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 127.0.0.1, port_value: 19000 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_http
codec_type: HTTP2
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/protobuf.User" }
route: { cluster: xds_cluster }
http_filters:
- name: envoy.router
clusters:
- name: xds_cluster
connect_timeout: { seconds: 1 }
type: STATIC
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
hosts:
- socket_address: { address: 127.0.0.1, port_value: 18000 }
- socket_address: { address: 127.0.0.1, port_value: 17000 }
health_checks:
- grpc_health_check: {service_name: YourServiceName}
unhealthy_threshold : 1
healthy_threshold: 1
timeout: 0.5s
interval: 0.5s
interval_jitter: 0.5s
复制代码
这是一个静态的路由配置,带grpc健康检查, 有四个关键点