Skip to content

Commit 833d454

Browse files
committed
test: add Example_direct_queue testing
1 parent 287ed91 commit 833d454

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

rabbitmq_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,34 @@ func TestJobComplete(t *testing.T) {
316316
assert.Error(t, err)
317317
assert.Equal(t, errors.New("job completed"), err)
318318
}
319+
320+
func Example_direct_queue() {
321+
m := mockMessage{
322+
Message: "foo",
323+
}
324+
w := NewWorker(
325+
WithSubj("direct_queue"),
326+
WithRoutingKey("direct_queue"),
327+
WithTag("direct_queue"),
328+
WithRunFunc(func(ctx context.Context, m core.QueuedMessage) error {
329+
fmt.Println("get data:", string(m.Bytes()))
330+
return nil
331+
}),
332+
)
333+
q, err := queue.NewQueue(
334+
queue.WithWorker(w),
335+
queue.WithWorkerCount(1),
336+
)
337+
if err != nil {
338+
w.opts.logger.Error(err)
339+
}
340+
341+
q.Start()
342+
time.Sleep(200 * time.Millisecond)
343+
q.Queue(m)
344+
time.Sleep(200 * time.Millisecond)
345+
q.Release()
346+
347+
// Output:
348+
// get data: foo
349+
}

0 commit comments

Comments
 (0)