-
Notifications
You must be signed in to change notification settings - Fork 21
/
settlehandler_example_test.go
44 lines (38 loc) · 1.16 KB
/
settlehandler_example_test.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
package shuttle_test
import (
"context"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus"
"github.com/Azure/go-shuttle/v2"
)
func ExampleNewSettlementHandler() {
tokenCredential, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
panic(err)
}
client, err := azservicebus.NewClient("myservicebus.servicebus.windows.net", tokenCredential, nil)
if err != nil {
panic(err)
}
receiver, err := client.NewReceiverForSubscription("topic-a", "sub-a", nil)
if err != nil {
panic(err)
}
lockRenewalInterval := 10 * time.Second
p := shuttle.NewProcessor(receiver,
shuttle.NewPanicHandler(nil,
shuttle.NewRenewLockHandler(&shuttle.LockRenewalOptions{Interval: &lockRenewalInterval},
shuttle.NewSettlementHandler(nil, mySettlingHandler()))), &shuttle.ProcessorOptions{MaxConcurrency: 10})
ctx, cancel := context.WithCancel(context.Background())
err = p.Start(ctx)
if err != nil {
panic(err)
}
cancel()
}
func mySettlingHandler() shuttle.Settler {
return func(ctx context.Context, message *azservicebus.ReceivedMessage) shuttle.Settlement {
return &shuttle.Complete{}
}
}