Started implementation of direct gets by subject

This commit is contained in:
Jeremy Saenz
2022-08-03 09:50:45 -07:00
parent 59d7d9ccc7
commit 1eb8a22c21
2 changed files with 17 additions and 0 deletions

3
js.go
View File

@@ -169,6 +169,9 @@ const (
// apiMsgGetT is the endpoint to perform a direct get of a message. // apiMsgGetT is the endpoint to perform a direct get of a message.
apiDirectMsgGetT = "DIRECT.GET.%s" apiDirectMsgGetT = "DIRECT.GET.%s"
// apiDirectMsgGetLastBySubjectT is the endpoint to perform a direct get of a message by subject.
apiDirectMsgGetLastBySubjectT = "DIRECT.GET.%s.%s"
// apiMsgDeleteT is the endpoint to remove a message. // apiMsgDeleteT is the endpoint to remove a message.
apiMsgDeleteT = "STREAM.MSG.DELETE.%s" apiMsgDeleteT = "STREAM.MSG.DELETE.%s"

14
jsm.go
View File

@@ -887,6 +887,20 @@ func (js *js) getMsg(name string, mreq *apiMsgGetRequest, opts ...JSOpt) (*RawSt
} }
var apiSubj string var apiSubj string
doDirectGetLastBySubject := o.directGet && mreq.LastFor != ""
if doDirectGetLastBySubject && js.nc.serverMinVersion(2, 9, 0) {
apiSubj = apiDirectMsgGetLastBySubjectT
dsSubj := js.apiSubj(fmt.Sprintf(apiSubj, name, mreq.LastFor))
r, err := js.apiRequestWithContext(o.ctx, dsSubj, nil)
if err != nil {
return nil, err
}
return convertDirectGetMsgResponseToMsg(name, r)
}
if o.directGet { if o.directGet {
apiSubj = apiDirectMsgGetT apiSubj = apiDirectMsgGetT
mreq.NextFor = o.directNextFor mreq.NextFor = o.directNextFor