MCPcopy Create free account
hub / github.com/dataddo/pgq / ExampleNewConsumer

Function ExampleNewConsumer

examples_test.go:16–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14var db *sql.DB
15
16func ExampleNewConsumer() {
17 slogger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
18 c, err := pgq.NewConsumer(db, "queue_name", &Handler{},
19 pgq.WithLockDuration(10*time.Minute),
20 pgq.WithPollingInterval(500*time.Millisecond),
21 pgq.WithAckTimeout(5*time.Second),
22 pgq.WithMessageProcessingReserveDuration(5*time.Second),
23 pgq.WithMaxParallelMessages(42),
24 pgq.WithMetrics(noop.Meter{}),
25 pgq.WithHistoryLimit(24*time.Hour),
26 pgq.WithLogger(slogger),
27 pgq.WithInvalidMessageCallback(func(ctx context.Context, msg pgq.InvalidMessage, err error) {
28 // message Payload and/or Metadata are not JSON object.
29 // The message will be discarded.
30 slogger.Warn("invalid message",
31 "error", err,
32 "msg.id", msg.ID,
33 )
34 }),
35 )
36 _, _ = c, err
37}
38
39func ExampleNewPublisher() {
40 hostname, _ := os.Hostname()

Callers

nothing calls this directly

Calls 10

NewConsumerFunction · 0.92
WithLockDurationFunction · 0.92
WithPollingIntervalFunction · 0.92
WithAckTimeoutFunction · 0.92
WithMaxParallelMessagesFunction · 0.92
WithMetricsFunction · 0.92
WithHistoryLimitFunction · 0.92
WithLoggerFunction · 0.92

Tested by

no test coverage detected