Launch Week Day 4: Introducing Data Exports.Learn More
Socket
Book a DemoSign in
Socket

trpc.group/trpc-go/trpc-naming-consul

Package Overview
Dependencies
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trpc.group/trpc-go/trpc-naming-consul

Go Modules
Version
v1.0.0
Version published
Created
Source

tRPC Consul 名字服务

Go Reference Go Report Card LICENSE Releases Docs Tests Coverage

关于 consul

HashiCorp - Consul

示例

配置:

plugins:
  naming:
    consul:
      address: dev.cloud.com:8500
      services:
        - trpc.test.helloworld.Greeter  # 一定要与 trpc service 相同
      register:  #  默认注册配置,上面的 services 会使用
        interval: 1s
        timeout: 1s
        tags:
          - test
        meta:
          appid: 1
        weight: 10
        deregister_critical_service_after: 10m
      services_register:  # 独立注册配置,不同服务可以有不同配置
        - service: trpc.test.helloworld.Greeter  # 一定要与 trpc service 相同
          register:  #  默认注册配置,上面的 services 会使用
            interval: 1s
            timeout: 1s
            tags:
              - test
            meta:
              appid: 1
            weight: 10
            deregister_critical_service_after: 10m
      selector:
        loadBalancer: random

client:  # 客户端调用的后端配置
  service:  # 针对单个后端的配置
    - callee: trpc.test.helloworld.Greeter  # 后端服务协议文件的 service name, 如何 callee 和下面的 name 一样,那只需要配置一个即可
      target: consul://trpc.test.helloworld.Greeter  # 后端服务地址 consul
      network: tcp  # 后端服务的网络类型 tcp udp
      protocol: http  # 应用层协议 trpc http
      timeout: 10000  # 请求最长处理时间
      serialization: 2  # 序列化方式 0-pb 2-json 3-flatbuffer,默认不要配置

main 入口:

package main

import (
  trpc  "trpc.group/trpc-go/trpc-go"
    "trpc.group/trpc-go/trpc-go/server"
    _ "trpc.group/trpc-go/trpc-naming-consul"
)

func main() {
    s := trpc.NewServer()
    // do sth ...
    
    s.Serve()
}

FAQs

Package last updated on 17 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts