diff --git a/providers/nats/nats.go b/providers/nats/nats.go index 42c5495..595c2b4 100644 --- a/providers/nats/nats.go +++ b/providers/nats/nats.go @@ -2,6 +2,8 @@ package nats import ( "context" + "fmt" + "time" "github.com/nats-io/nats.go" ) @@ -29,3 +31,17 @@ func (d *DotNats) Subscribe(subject string) (<-chan *nats.Msg, error) { func (d *DotNats) Publish(subject, message string) error { return d.conn.Publish(subject, []byte(message)) } + +func (d *DotNats) Request(subject, data string, timeout_ ...time.Duration) (*nats.Msg, error) { + var timeout time.Duration + switch len(timeout_) { + case 0: + timeout = 1 * time.Second + case 1: + timeout = timeout_[0] + default: + return nil, fmt.Errorf("too many timeout args") + } + + return d.conn.Request(subject, []byte(data), timeout) +}