8000 Add max delivery opts by davidwin93 · Pull Request #2 · sl1pm4t/gongs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add max delivery opts #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions generic_queue.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,28 @@ func (s *GenericStream[T, I]) GetLastMsg(name string) (*T, error) {
}

func (s *GenericStream[T, I]) QueueSubscribe(queue string, fn MsgHandlerFunc[T]) (*nats.Subscription, error) {
return s.QueueSubscribeWithOpts(queue, fn)
}

func (s *GenericStream[T, I]) QueueSubscribeWithOpts(queue string, fn MsgHandlerFunc[T], opts ...nats.SubOpt) (*nats.Subscription, error) {
sub, err := s.js.QueueSubscribe(s.subject, queue,
func(msg *nats.Msg) {
se, err := s.decodeMsg(msg)

if err != nil {
// dump msg
msg.Ack()
return
}

evt := (*T)(se)
err = fn(evt)
if err != nil {
msg.Nak()
}
msg.Ack()
},
opts...,
)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deleti 8000 ons generic_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package gongs_test
import (
"encoding/json"
"fmt"
"sync"
"testing"

"github.com/nats-io/nats.go"
"github.com/sl1pm4t/gongs"
"github.com/sl1pm4t/gongs/test"
"sync"
"testing"
)

type TestStreamMsg struct {
Expand Down Expand Up @@ -64,7 +65,6 @@ func Test_GenericStream_QueueSubscribe(t *testing.T) {
)

wg := sync.WaitGroup{}

sub, err := workStream.QueueSubscribe("test-workers", func(evt *TestStreamMsg) error {
defer wg.Done()
t.Logf("Test Event: %d - %s\n", evt.eventData.Id, evt.eventData.Foo)
Expand Down
0