Created
July 20, 2019 16:59
-
-
Save ripienaar/5e8f89f34897b8a55ced155e39360eeb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"fmt" | |
"strings" | |
"time" | |
"github.com/choria-io/go-choria/choria" | |
"github.com/choria-io/go-client/discovery/broadcast" | |
"github.com/choria-io/go-config" | |
"github.com/choria-io/go-protocol/protocol" | |
"github.com/choria-io/mcorpc-agent-provider/mcorpc/client" | |
ddl "github.com/choria-io/mcorpc-agent-provider/mcorpc/ddl/agent" | |
) | |
func panicIfError(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
func main() { | |
cfg, err := config.NewConfig("node.conf") | |
panicIfError(err) | |
cfg.DisableTLS = true | |
cfg.DisableSecurityProviderVerify = true | |
protocol.Secure = "false" | |
cfg.Choria.SSLDir = "/nonexisting" | |
cfg.LogLevel = "warn" | |
fw, err := choria.NewWithConfig(cfg) | |
panicIfError(err) | |
log := fw.Logger("rpcping") | |
addl, err := ddl.New("rpcutil.json") | |
panicIfError(err) | |
rpc, err := client.New(fw, "rpcutil", client.DDL(addl)) | |
panicIfError(err) | |
ctx, cancel := context.WithCancel(context.Background()) | |
defer cancel() | |
fmt.Print("Performing discovery....") | |
b := broadcast.New(fw) | |
nodes, err := b.Discover(ctx, broadcast.Filter(protocol.NewFilter()), broadcast.Timeout(time.Second)) | |
panicIfError(err) | |
fmt.Printf("%d\n", len(nodes)) | |
resp, err := rpc.Do(ctx, "ping", "{}", client.Workers(1), client.Targets(nodes), client.ReplyHandler(func(r protocol.Reply, rpcr *client.RPCReply) { | |
fmt.Printf("%s got reply from %s\n", r.RequestID(), r.SenderID()) | |
})) | |
panicIfError(err) | |
stat := resp.Stats() | |
if len(stat.NoResponseFrom()) > 0 { | |
log.Errorf("Did not get any responses from: %s", strings.Join(stat.NoResponseFrom(), ", ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment