diff --git a/router/default.go b/router/default.go index 5d20b953..552f06da 100644 --- a/router/default.go +++ b/router/default.go @@ -467,9 +467,11 @@ func (r *router) start() error { return nil } - // add all local service routes into the routing table - if err := r.manageRegistryRoutes(r.options.Registry, "create"); err != nil { - return fmt.Errorf("failed adding registry routes: %s", err) + if r.options.Prewarm { + // add all local service routes into the routing table + if err := r.manageRegistryRoutes(r.options.Registry, "create"); err != nil { + return fmt.Errorf("failed adding registry routes: %s", err) + } } // add default gateway into routing table diff --git a/router/options.go b/router/options.go index 94c96c07..cba10356 100644 --- a/router/options.go +++ b/router/options.go @@ -23,6 +23,8 @@ type Options struct { Advertise Strategy // Context for additional options Context context.Context + // Prewarm the route table on router startup + Prewarm bool } // Id sets Router Id @@ -60,13 +62,20 @@ func Registry(r registry.Registry) Option { } } -// Strategy sets route advertising strategy +// Advertise sets route advertising strategy func Advertise(a Strategy) Option { return func(o *Options) { o.Advertise = a } } +// Prewarm sets whether to prewarm the route table +func Prewarm(b bool) Option { + return func(o *Options) { + o.Prewarm = b + } +} + // DefaultOptions returns router default options func DefaultOptions() Options { return Options{