Skip to content

Commit

Permalink
(choria-io#1802) support passing the inbox prefix to nats cli
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Sep 2, 2022
1 parent d21ca54 commit e017b2f
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 129 deletions.
2 changes: 1 addition & 1 deletion aagent/watchers/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/choria-io/go-choria/backoff"
"github.com/choria-io/go-choria/internal/util"
"github.com/choria-io/go-choria/lifecycle"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
"github.com/tidwall/gjson"
)

Expand Down
2 changes: 2 additions & 0 deletions broker/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func (s *stubConnection) ConnectionStats() nats.Statistics {
return nats.Statistics{}
}

func (s *stubConnection) InboxPrefix() string { return "_INBOX.>" }

func (s *stubConnection) IsConnected() bool { return true }

func (s *stubConnection) Unsubscribe(name string) error {
Expand Down
15 changes: 11 additions & 4 deletions choria/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,11 @@ func (conn *Connection) Connect(ctx context.Context) (err error) {
}),
}

prefix := conn.InboxPrefix()
if conn.uniqueId != "" {
prefix := fmt.Sprintf("%s.reply.%s", conn.config.MainCollective, conn.uniqueId)
conn.log.Infof("Setting custom inbox prefix based on unique ID to %s", prefix)
options = append(options, nats.CustomInboxPrefix(prefix))
} else {
options = append(options, nats.CustomInboxPrefix(fmt.Sprintf("%s.reply", conn.config.MainCollective)))
}
options = append(options, nats.CustomInboxPrefix(prefix))

if !conn.fw.Config.InitiatedByServer {
options = append(options, nats.PingInterval(30*time.Second))
Expand Down Expand Up @@ -735,6 +733,15 @@ func (conn *Connection) Flush() {
conn.nats.Flush()
}

// InboxPrefix is the subject prefix used for replies
func (conn *Connection) InboxPrefix() string {
if conn.uniqueId != "" {
return fmt.Sprintf("%s.reply.%s", conn.config.MainCollective, conn.uniqueId)
} else {
return fmt.Sprintf("%s.reply", conn.config.MainCollective)
}
}

// Close closes the NATS connection after flushing what needed to be sent
func (conn *Connection) Close() {
subs := []string{}
Expand Down
2 changes: 2 additions & 0 deletions cmd/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func (b *brokerCommand) prepareNatsCli(pc *fisk.ParseContext, opts *natscli.Opti
natscli.SetLogger(logger)

opts.Conn = conn.Nats()
opts.InboxPrefix = conn.InboxPrefix()

opts.JSc, err = opts.Conn.JetStream()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovAddCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/choria-io/go-choria/config"
"github.com/choria-io/go-choria/internal/util"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovAPICommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/choria-io/go-choria/internal/util"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovDeleteCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_evict.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/choria-io/go-choria/lifecycle"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovEvictCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovResetCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/choria-io/go-choria/lifecycle"
"github.com/kballard/go-shellquote"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovRunCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/governor_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/choria-io/go-choria/choria"
"github.com/choria-io/go-choria/internal/util"
"github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/governor"
"github.com/nats-io/jsm.go/governor" //lint:ignore SA1019 Will vendor
)

type tGovViewCommand struct {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ require (
github.com/looplab/fsm v0.3.0
github.com/miekg/pkcs11 v1.1.1
github.com/mitchellh/mapstructure v1.5.0
github.com/nats-io/jsm.go v0.0.34-0.20220819130354-30ace5d49ea8
github.com/nats-io/nats-server/v2 v2.8.5-0.20220831135813-4b9db05a0cba
github.com/nats-io/jsm.go v0.0.34-0.20220902100732-f238d2edcd1f
github.com/nats-io/nats-server/v2 v2.8.5-0.20220901192829-c4b5ca7cff77
github.com/nats-io/nats.go v1.16.1-0.20220901120628-84e2c74b56da
github.com/nats-io/natscli v0.0.34-0.20220824061610-7c31f06231d3
github.com/nats-io/natscli v0.0.34-0.20220902113825-755db5fe7ed9
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.2
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -837,16 +837,16 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nats-io/jsm.go v0.0.34-0.20220819130354-30ace5d49ea8 h1:k7lZgjWPxY7Kyjwuc0AF9I3iaEPq3ccAJiwIydmT8zs=
github.com/nats-io/jsm.go v0.0.34-0.20220819130354-30ace5d49ea8/go.mod h1:77Om9glk747jR7WeG9DgDCpWC2h88s2O9w5lVud4lUk=
github.com/nats-io/jsm.go v0.0.34-0.20220902100732-f238d2edcd1f h1:i0d4TugIh+1RBBxv3x/gJ6Gwsocj6CzfqSKQUkI5BC0=
github.com/nats-io/jsm.go v0.0.34-0.20220902100732-f238d2edcd1f/go.mod h1:ueH1xXyvo90DD3dhNswKCcjB6MGvnj2HeMn/dimskck=
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220831135813-4b9db05a0cba h1:mSl+YL/a0MIeWaedIZZgJBgr8XWY+SHP36S8LyTTy3E=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220831135813-4b9db05a0cba/go.mod h1:+f++B/5jpr71JATt7b5KCX+G7bt43iWx1OYWGkpE/Kk=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220901192829-c4b5ca7cff77 h1:BsOzAZ/yTUQKQxVVTjwLtM7T0j2XXkPICBjgOPY6bfU=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220901192829-c4b5ca7cff77/go.mod h1:+f++B/5jpr71JATt7b5KCX+G7bt43iWx1OYWGkpE/Kk=
github.com/nats-io/nats.go v1.16.1-0.20220901120628-84e2c74b56da h1:VAeFGKLEHSiVb1nPowftbJCF7YQYXHyOsr+Mun0i4+c=
github.com/nats-io/nats.go v1.16.1-0.20220901120628-84e2c74b56da/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/natscli v0.0.34-0.20220824061610-7c31f06231d3 h1:r1Swk5S8clYZ7hh0S8ZRJlmLZxBbk+awBrIvo9cqPwA=
github.com/nats-io/natscli v0.0.34-0.20220824061610-7c31f06231d3/go.mod h1:qBdPIG5pYttk3UPjZ+c+tyTIowoA+2cEpEsc2UUWB9Q=
github.com/nats-io/natscli v0.0.34-0.20220902113825-755db5fe7ed9 h1:imCC8XkB9sXUfHiRH+DbjcdOD/WPM0fgHtCY80T3mXw=
github.com/nats-io/natscli v0.0.34-0.20220902113825-755db5fe7ed9/go.mod h1:ZabDo4FZlKm5eFUR5LD3W0+aNA0U+iBh5jnIOBxMhs8=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand Down
1 change: 1 addition & 0 deletions inter/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Connector interface {
ConnectedServer() string
ConnectionOptions() nats.Options
ConnectionStats() nats.Statistics
InboxPrefix() string
IsConnected() bool
Nats() *nats.Conn
NodeDirectedTarget(collective string, identity string) string
Expand Down
1 change: 1 addition & 0 deletions inter/connector_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ type ConnectorInfo interface {
ConnectedServer() string
ConnectionOptions() nats.Options
ConnectionStats() nats.Statistics
InboxPrefix() string
}
38 changes: 26 additions & 12 deletions inter/imocks/connector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions inter/imocks/connector_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions inter/imocks/ddl_resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e017b2f

Please sign in to comment.