Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/subscribe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/skvoch/nats-cli/pkg/constants"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -14,6 +15,7 @@ var subscribeVars struct {
natsServer string
natsSubject string
natsClusterID string
natsClientID string
templateName string
startDeltaFrom time.Duration
}
Expand All @@ -33,6 +35,7 @@ var subscribeTemplateCmd = &cobra.Command{
if err := subscribe.Run(
tpl.NatsServer,
tpl.NatsClusterID,
tpl.NatsClientID,
tpl.NatsSubject,
subscribeVars.startDeltaFrom); err != nil {
logrus.Error(err)
Expand All @@ -52,6 +55,7 @@ var subscribeCmd = &cobra.Command{
if err := subscribe.Run(
subscribeVars.natsServer,
subscribeVars.natsClusterID,
subscribeVars.natsClientID,
subscribeVars.natsSubject,
subscribeVars.startDeltaFrom); err != nil {
logrus.Error(err)
Expand All @@ -72,6 +76,7 @@ func init() {
subscribeCmd.Flags().StringVarP(&subscribeVars.natsServer, "addr", "a", "", "NATS server addr")
subscribeCmd.Flags().StringVarP(&subscribeVars.natsSubject, "subject", "s", "", "subject name")
subscribeCmd.Flags().StringVarP(&subscribeVars.natsClusterID, "cluster-id", "c", "", "cluster id")
subscribeCmd.Flags().StringVarP(&subscribeVars.natsClientID, "client-id", "i", constants.ClientID, "client id")
subscribeCmd.Flags().DurationVarP(&subscribeVars.startDeltaFrom, "delta-time", "d", 0, "delta-time")

if err := subscribeCmd.MarkFlagRequired("addr"); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package cmd

import (
"fmt"

"github.com/sirupsen/logrus"
"github.com/skvoch/nats-cli/internal/template"
"github.com/skvoch/nats-cli/pkg/constants"
"github.com/spf13/cobra"
)

type TemplateVars struct {
natsServer string
natsSubject string
natsClusterID string
natsClientID string
name string
}

Expand Down Expand Up @@ -57,6 +58,7 @@ var templateCreate = &cobra.Command{
if err := template.Add(templateVars.name, template.Item{
NatsClusterID: templateVars.natsClusterID,
NatsServer: templateVars.natsServer,
NatsClientID: templateVars.natsClientID,
NatsSubject: templateVars.natsSubject,
}); err != nil {
logrus.Error(err)
Expand All @@ -80,8 +82,8 @@ var templateList = &cobra.Command{
templates := template.List()

for name, item := range templates.Values {
str := fmt.Sprintf(`name: %s | server: %s | cluster-id: %s | subject: %s`,
name, item.NatsServer, item.NatsClusterID, item.NatsSubject)
str := fmt.Sprintf(`name: %s | server: %s | cluster-id: %s | client-id: %s | subject: %s`,
name, item.NatsServer, item.NatsClusterID, item.NatsClientID, item.NatsSubject)
logrus.Info(str)
}

Expand All @@ -99,6 +101,7 @@ func init() {
templateCreate.Flags().StringVarP(&templateVars.natsServer, "addr", "a", "", "NATS server addr")
templateCreate.Flags().StringVarP(&templateVars.natsSubject, "subject", "s", "", "subject name")
templateCreate.Flags().StringVarP(&templateVars.natsClusterID, "cluster-id", "c", "", "cluster id")
templateCreate.Flags().StringVarP(&templateVars.natsClientID, "client-id", "i", constants.ClientID, "client id")

if err := templateCreate.MarkFlagRequired("addr"); err != nil {
logrus.Fatal(err)
Expand Down
10 changes: 7 additions & 3 deletions internal/subscribe/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ const (
logNatsSubject = "subject"
)

func Run(address, clusterId, subject string, delta time.Duration) error {
func Run(address, clusterId, clientId, subject string, delta time.Duration) error {
if clientId == "" {
clientId = constants.ClientID
}

logrus.WithField(logNatsAddr, address).Info("trying connect to nats...")
nats, err := natsc.Connect(address, clusterId, constants.ClientID)
nats, err := natsc.Connect(address, clusterId, clientId)
if err != nil {
return err
}
Expand All @@ -32,7 +36,7 @@ func Run(address, clusterId, subject string, delta time.Duration) error {
}
logrus.WithField(logNatsSubject, subject).Info("successful subscription to subject!")

c := make(chan os.Signal)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)

for {
Expand Down
1 change: 1 addition & 0 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Item struct {
NatsServer string
NatsSubject string
NatsClusterID string
NatsClientID string
}

type Templates struct {
Expand Down