-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPRESENTATION.slide
126 lines (84 loc) · 2.71 KB
/
PRESENTATION.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
netx
Semantic Addressing Extension for Go's net Package
12:14 10 Apr 2017
Tags: microservice, net, http, grpc
Philipp Brüll
Developer, simia.tech
https://simia.tech
* Micro-services toolkits
- go-kit
- micro
- gizmo
- Kite
Define interfaces and some implementation for transport, configuration, metrics, ...
* The gopher's BFF: standard library
* github.com/simia-tech/netx
- Focus on the transport
- Implements semantic addressing
- No new interfaces - uses `net.Listener` and `net.Conn`
- Drop-in replacement of `net.Listen` and `net.Dial`
* Drop-in replacement
The calls
listener, err := net.Listen("tcp", "localhost:8080")
conn, err := net.Dial("tcp", "localhost:8080")
can be replaced by
listener, err := netx.Listen("tcp", "localhost:8080")
conn, err := netx.Dial("tcp", "localhost:8080")
It'll do exactly the same.
* Provides more "networks"
import _ "github.com/simia-tech/netx/network/nats"
listener, err := netx.Listen("nats", "echo", netx.Nodes("nats://localhost:4222"))
conn, err := netx.Dial("nats", "echo", netx.Nodes("nats://localhost:4222"))
Current implementations are `consul`, `dnssrv`, `nats` and `quic`.
* nats
- Implementations for `Listen` and `Dial`
- Basically `tcp` over nats
- Uses queue groups to select instance node
- Balancing and fail-over is done via queue groups
- Used in production
* consul
- Implementations for `Listen` and `Dial`
- Custom balancing using the `Balancer` option
- Not much tested
* dnssrv
- Implementation only for `Dial`
- Custom balancing using the `Balancer` option
- Not much tested
* quic
- No semantic addressing
- Experimental
* HTTP
listener, _ := netx.Listen("nats", "greeter", netx.Nodes("nats://localhost:4222"))
mux := &http.ServeMux{}
mux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello")
})
server := &http.Server{Handler: mux}
go func() {
server.Serve(listener)
}()
client := &http.Client{
Transport: netx.NewHTTPTransport("nats", netx.Nodes("nats://localhost:4222")),
}
response, _ := client.Get("http://greeter/hello")
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(body))
// Output: Hello
* GRPC
listener, _ := netx.Listen("nats", "echo", netx.Nodes("nats://localhost:4222"))
server := grpc.NewServer()
model.Register...(server, ...)
go func() {
if err := server.Serve(listener); err != nil {
log.Println(err)
}
}()
conn, _ := grpc.Dial("echo",
grpc.WithDialer(netx.NewGRPCDialer("nats", netx.Nodes("nats://localhost:4222"))))
* ToDo
- more testing (`github.com/simia-tech/netx/test`)
- quic!
- other implementations
- multicast?