@@ -5,20 +5,27 @@ open System.Threading.Tasks
5
5
open Azure.Messaging .ServiceBus
6
6
open Azure.Messaging .ServiceBus .Administration
7
7
8
+ type ChannelOptions =
9
+ { Prefetch: uint16 option // optional prefetch limit
10
+ IgnoreDuplicates: bool
11
+ TempIdle: TimeSpan } // temporary queue idle lifetime
12
+ static member Default =
13
+ { Prefetch = None
14
+ TempIdle = TimeSpan.FromMinutes 5.
15
+ IgnoreDuplicates = true }
16
+
8
17
[<RequireQualifiedAccess>]
9
18
[<CompilationRepresentation( CompilationRepresentationFlags.ModuleSuffix) >]
10
19
module Channels =
11
20
/// constructs event-stream publishers and consumers.
12
21
/// mkClient: function to construct the client.
13
22
/// mkAdminClient: function to construct the admin client.
14
23
/// log: function for diagnostics logging.
15
- /// prefetch: optional prefetch limit.
16
- /// tempIdle: temporary queue idle lifetime.
24
+ /// options: channel options.
17
25
let mkNew ( mkClient : unit -> ServiceBusClient )
18
26
( mkAdminClient : unit -> ServiceBusAdministrationClient )
19
27
( log : Log )
20
- ( prefetch : uint16 option )
21
- ( tempIdle : TimeSpan ) =
28
+ ( options : ChannelOptions ) =
22
29
let client = lazy mkClient()
23
30
let adminClient = lazy mkAdminClient()
24
31
let withClient cont = cont client.Value
@@ -32,23 +39,23 @@ module Channels =
32
39
let renew = Consumer.Renewable.mkNew binding.Subscription.LockDuration
33
40
binding.Subscription.LockDuration <- min binding.Subscription.LockDuration Consumer.Renewable.maxLockDuration
34
41
Subscription.withBinding log withAdminClient binding,
35
- ServiceBusReceiverOptions ( ReceiveMode = ServiceBusReceiveMode.PeekLock),
42
+ Consumer.Options ( ReceiveMode = ServiceBusReceiveMode.PeekLock),
36
43
renew
37
44
| Persistent ( queueOptions, bindings) ->
38
45
let renew = Consumer.Renewable.mkNew queueOptions.LockDuration
39
46
queueOptions.LockDuration <- min queueOptions.LockDuration Consumer.Renewable.maxLockDuration
40
47
Queue.withBindings log withAdminClient queueOptions bindings,
41
- ServiceBusReceiverOptions ( ReceiveMode = ServiceBusReceiveMode.PeekLock),
48
+ Consumer.Options ( ReceiveMode = ServiceBusReceiveMode.PeekLock),
42
49
renew
43
50
| Temporary bindings ->
44
- Queue.withBindings log withAdminClient ( CreateQueueOptions( Guid.NewGuid() .ToString(), AutoDeleteOnIdle = tempIdle )) bindings,
45
- ServiceBusReceiverOptions ( ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete),
51
+ Queue.withBindings log withAdminClient ( CreateQueueOptions( Guid.NewGuid() .ToString(), AutoDeleteOnIdle = options.TempIdle )) bindings,
52
+ Consumer.Options ( ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete),
46
53
Consumer.Renewable.noop
47
54
| DeadLetter path ->
48
55
( fun cont -> Task.FromResult path |> cont),
49
- ServiceBusReceiverOptions ( ReceiveMode = ServiceBusReceiveMode.PeekLock, SubQueue = SubQueue.DeadLetter),
56
+ Consumer.Options ( ReceiveMode = ServiceBusReceiveMode.PeekLock, SubQueue = SubQueue.DeadLetter),
50
57
Consumer.Renewable.noop
51
- prefetch |> Option.iter ( fun v -> receiveOptions.PrefetchCount <- int v)
58
+ options.Prefetch |> Option.iter ( fun v -> receiveOptions.PrefetchCount <- int v)
52
59
Consumer.mkNew receiveOptions renew ofRecevied withClient withBindings
53
60
54
61
member __.GetPublisher < 'msg > toSend ( Topic topic ) : Publisher < 'msg > =
@@ -72,12 +79,14 @@ module Channels =
72
79
73
80
/// Build an instance using FQDN of the namespace and Azure TokenCredential
74
81
let fromFqdn ( fqNamespace : string ) ( credential : Azure.Core.TokenCredential ) ( log : Log ) =
75
- mkNew ( fun _ -> ServiceBusClient( fqNamespace, credential))
76
- ( fun _ -> ServiceBusAdministrationClient( fqNamespace, credential))
77
- log None ( TimeSpan.FromMinutes 5. )
82
+ ChannelOptions.Default
83
+ |> mkNew ( fun _ -> ServiceBusClient( fqNamespace, credential))
84
+ ( fun _ -> ServiceBusAdministrationClient( fqNamespace, credential))
85
+ log
78
86
79
87
/// Build an instance using connection string
80
88
let fromConnectionString ( connString : string ) ( log : Log ) =
81
- mkNew ( fun _ -> ServiceBusClient connString)
82
- ( fun _ -> ServiceBusAdministrationClient connString)
83
- log None ( TimeSpan.FromMinutes 5. )
89
+ ChannelOptions.Default
90
+ |> mkNew ( fun _ -> ServiceBusClient connString)
91
+ ( fun _ -> ServiceBusAdministrationClient connString)
92
+ log
0 commit comments