()
| 15 | } |
| 16 | |
| 17 | func ExamplePublisher() { |
| 18 | db, err := sql.Open("postgres", "user=postgres password=postgres host=localhost port=5432 dbname=postgres") |
| 19 | if err != nil { |
| 20 | log.Fatal("Error opening database:", err) |
| 21 | } |
| 22 | defer db.Close() |
| 23 | const queueName = "test_queue" |
| 24 | p := pgq.NewPublisher(db) |
| 25 | payload, _ := json.Marshal(PayloadStruct{Foo: "bar"}) |
| 26 | messages := []*pgq.MessageOutgoing{ |
| 27 | { |
| 28 | Metadata: pgq.Metadata{ |
| 29 | "version": "1.0", |
| 30 | }, |
| 31 | Payload: json.RawMessage(payload), |
| 32 | }, |
| 33 | { |
| 34 | Metadata: pgq.Metadata{ |
| 35 | "version": "1.0", |
| 36 | }, |
| 37 | Payload: json.RawMessage(payload), |
| 38 | }, |
| 39 | { |
| 40 | Metadata: pgq.Metadata{ |
| 41 | "version": "1.0", |
| 42 | }, |
| 43 | Payload: json.RawMessage(payload), |
| 44 | }, |
| 45 | } |
| 46 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 47 | defer cancel() |
| 48 | ids, err := p.Publish(ctx, queueName, messages...) |
| 49 | if err != nil { |
| 50 | log.Fatal("Error publishing message:", err) |
| 51 | } |
| 52 | log.Println("Published messages with ids:", ids) |
| 53 | } |
nothing calls this directly
no test coverage detected