Created
December 27, 2017 04:40
-
-
Save guoyoujin/a9847247d2162dd1e14f3b7057f4fde6 to your computer and use it in GitHub Desktop.
rpcx etcd tls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// go run -tags etcd client.go | |
package main | |
import ( | |
"context" | |
"flag" | |
"log" | |
"time" | |
"crypto/tls" | |
"io/ioutil" | |
"crypto/x509" | |
"github.com/docker/libkv/store" | |
example "github.com/rpcx-ecosystem/rpcx-examples3" | |
"github.com/smallnest/rpcx/client" | |
) | |
var ( | |
// etcdAddr = flag.String("etcdAddr", "110.210.114.227:2379", "etcd address") | |
etcdAddr = flag.String("etcdAddr", "110.210.114.227:2379", "etcd address") | |
basePath = flag.String("base", "/rpcx_test", "prefix path") | |
) | |
func main() { | |
flag.Parse() | |
cert, err_0 := ioutil.ReadFile("/home/tongxin/project/etcd/etcd-root-ca.pem") | |
if err_0 != nil { | |
log.Fatalf("Couldn't load file", err_0) | |
} | |
certPool := x509.NewCertPool() | |
certPool.AppendCertsFromPEM(cert) | |
conf := &tls.Config{ | |
RootCAs: certPool, | |
} | |
op := &store.Config{} | |
op.TLS = conf | |
d := client.NewEtcdDiscovery(*basePath, "Arith", []string{*etcdAddr}, op) | |
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption) | |
defer xclient.Close() | |
args := &example.Args{ | |
A: 10, | |
B: 20, | |
} | |
for { | |
reply := &example.Reply{} | |
err := xclient.Call(context.Background(), "Mul", args, reply) | |
if err != nil { | |
log.Printf("failed to call: %v\n", err) | |
time.Sleep(5 * time.Second) | |
continue | |
} | |
log.Printf("%d * %d = %d", args.A, args.B, reply.C) | |
time.Sleep(5 * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment