-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.go
50 lines (43 loc) · 1023 Bytes
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"github.com/yunussandikci/dbqueue-go/dbqueue"
"github.com/yunussandikci/dbqueue-go/dbqueue/types"
)
func main() {
//db := "postgres://postgres:root@localhost/example"
db := "example.db"
ctx := context.Background()
engine, connectErr := dbqueue.OpenSQLite(ctx, db)
if connectErr != nil {
panic(connectErr)
}
queue1, createErr := engine.CreateQueue(ctx, "example")
if createErr != nil {
panic(createErr)
}
go func() {
for i := 0; i < 100000; i++ {
sendErr := queue1.SendMessage(ctx, &types.Message{
Payload: []byte(fmt.Sprintf("Hello, %d", i)),
})
if sendErr != nil {
panic(sendErr)
}
}
}()
go func() {
receiverErr := queue1.ReceiveMessage(ctx, func(message types.ReceivedMessage) {
fmt.Println(string(message.Payload))
deleteErr := queue1.DeleteMessage(ctx, message.ID)
if deleteErr != nil {
panic(deleteErr)
}
}, types.ReceiveMessageOptions{})
if receiverErr != nil {
panic(receiverErr)
}
}()
select {}
}