diff --git a/protocol/nats_jetstream/v2/sender.go b/protocol/nats_jetstream/v2/sender.go index 2ed7fa2d2..c69f3cb95 100644 --- a/protocol/nats_jetstream/v2/sender.go +++ b/protocol/nats_jetstream/v2/sender.go @@ -50,15 +50,21 @@ func NewSenderFromConn(conn *nats.Conn, stream, subject string, jsmOpts []nats.J return nil, err } - streamInfo, err := jsm.StreamInfo(stream, jsmOpts...) - - if streamInfo == nil || err != nil && err.Error() == "stream not found" { - _, err = jsm.AddStream(&nats.StreamConfig{ - Name: stream, - Subjects: []string{stream + ".*"}, - }) - if err != nil { - return nil, err + // A Stream parameter is not needed for a send operation. + // A subject is all that is needed. + // Below, a stream is created with default stream config which may not be desired. + // It may be that the intention is for the call to fail if a stream does not exist. + if stream != "" { + streamInfo, err := jsm.StreamInfo(stream, jsmOpts...) + + if streamInfo == nil || err != nil && err.Error() == "stream not found" { + _, err = jsm.AddStream(&nats.StreamConfig{ + Name: stream, + Subjects: []string{stream + ".*"}, + }) + if err != nil { + return nil, err + } } }