• Fork

    Fork

    Example: fork

    Fork is a method of XClient and you can use it to send a request to all servers that contains this service.

    If any of servers returns response whithout an error, Fork will return for this XClient. If all servers return errors, Fork returns an error of those errors.

    It is like thee Failbackup mode. Failbackup uses at most two requests but Fork uses more requests (same to count of servers).

    1. func main() {
    2. ……
    3. xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption)
    4. defer xclient.Close()
    5. args := &example.Args{
    6. A: 10,
    7. B: 20,
    8. }
    9. for {
    10. reply := &example.Reply{}
    11. err := xclient.Fork(context.Background(), "Mul", args, reply)
    12. if err != nil {
    13. log.Fatalf("failed to call: %v", err)
    14. }
    15. log.Printf("%d * %d = %d", args.A, args.B, reply.C)
    16. time.Sleep(1e9)
    17. }
    18. }