Skip to content

Commit

Permalink
support domain in jsm
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed May 7, 2021
1 parent 46e47ce commit 3258ab5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion jsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ func IsValidName(n string) bool {
}

// APISubject returns API subject with prefix applied
func APISubject(subject string, prefix string) string {
func APISubject(subject string, prefix string, domain string) string {
if domain != "" {
return fmt.Sprintf("$JS.%s.API", domain)
}

if prefix == "" {
return subject
}
Expand Down
3 changes: 2 additions & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Manager struct {
validator api.StructValidator
apiPrefix string
eventPrefix string
domain string

sync.Mutex
}
Expand Down Expand Up @@ -444,7 +445,7 @@ func (m *Manager) Streams() (streams []*Stream, err error) {
}

func (m *Manager) apiSubject(subject string) string {
return APISubject(subject, m.apiPrefix)
return APISubject(subject, m.apiPrefix, m.domain)
}

// MetaLeaderStandDown requests the meta group leader to stand down, must be initiated by a system user
Expand Down
8 changes: 1 addition & 7 deletions natscontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,7 @@ func WithJSAPIPrefix(p string) Option {
}

// JSAPIPrefix is the subject prefix to use when accessing JetStream API
func (c *Context) JSAPIPrefix() string {
if c.config.JSDomain != "" {
return fmt.Sprintf("$JS.%s.API", c.config.JSDomain)
}

return c.config.JSAPIPrefix
}
func (c *Context) JSAPIPrefix() string { return c.config.JSAPIPrefix }

// WithJSEventPrefix sets the prefix to use for JetStream Events
func WithJSEventPrefix(p string) Option {
Expand Down
7 changes: 7 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ func WithEventPrefix(s string) Option {
o.eventPrefix = s
}
}

// WithDomain sets a JetStream domain, incompatible with WithApiPrefix()
func WithDomain(d string) Option {
return func(o *Manager) {
o.domain = d
}
}

0 comments on commit 3258ab5

Please sign in to comment.