🎉 Initial Commit
This commit is contained in:
51
pkg/shared/registrar/README.md
Normal file
51
pkg/shared/registrar/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Registrar
|
||||
|
||||
The Registrar is the service discovery system of the DysonNetwork.
|
||||
Here are a port to the Golang in order to support other Golang services.
|
||||
|
||||
To use the system, try build with these API:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"yourmodule/registry"
|
||||
)
|
||||
|
||||
func main() {
|
||||
endpoints := []string{"localhost:2379"}
|
||||
|
||||
registrar, err := registry.NewServiceRegistrar(endpoints)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating registrar: %v", err)
|
||||
}
|
||||
|
||||
serviceName := "orders"
|
||||
host := "10.0.0.5"
|
||||
port := 5000
|
||||
ttl := int64(30)
|
||||
|
||||
err = registrar.Register(serviceName, host, port, ttl)
|
||||
if err != nil {
|
||||
log.Fatalf("Register error: %v", err)
|
||||
}
|
||||
log.Println("Service registered")
|
||||
|
||||
// Wait for termination
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-stop
|
||||
|
||||
err = registrar.Deregister()
|
||||
if err != nil {
|
||||
log.Printf("Deregister error: %v", err)
|
||||
} else {
|
||||
log.Println("Service deregistered")
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user