Skip to content

Commit fce5e01

Browse files
stoftRasmus LarssonemilklassonMousaka
authored
Prefetch count configurability (#8)
* Add prefetchCount configurability. * Make prefetchCount have a default value of 10. Co-authored-by: Rasmus Larsson <[email protected]> Co-authored-by: Emil Klasson <[email protected]> Co-authored-by: Kristian Lundström <[email protected]>
1 parent dca83ba commit fce5e01

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Makefile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
PROJECT_NAME=Insurello.RabbitMqClient
2-
TEST_PROJECT_NAME=$(PROJECT_NAME).Tests
32
PROJECT_DIR=src/$(PROJECT_NAME)
4-
TEST_DIR=src/$(TEST_PROJECT_NAME)
53
MAIN_PROJ=$(MAIN_DIR)/$(PROJECT_NAME).fsproj
6-
TEST_PROJ=$(TEST_DIR)/$(TEST_PROJECT_NAME).fsproj
74

85

9-
.PHONY : all build test
6+
.PHONY : all build
107

11-
all: build test
8+
all: build
129

13-
test:
14-
dotnet test $(TEST_PROJ)
15-
16-
test-watch:
17-
dotnet watch --project $(TEST_DIR) run
10+
build:
11+
dotnet build
1812

1913
clean:
20-
rm -r $(PROJECT_DIR)/bin $(PROJECT_DIR)/obj $(TEST_DIR)/bin $(TEST_DIR)/obj
14+
rm -r $(PROJECT_DIR)/bin $(PROJECT_DIR)/obj

src/Insurello.RabbitMqClient/MqClient.fs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ module MqClient =
5757
Headers: Map<string, string>
5858
Content: Content }
5959

60-
type ChannelConfig =
61-
{ withConfirmSelect: bool }
60+
type private ChannelConfig =
61+
{ withConfirmSelect: bool
62+
prefetchCount: uint16 }
63+
64+
type PrefetchCount = PrefetchCount of uint16
6265

6366
let private contentTypeStringFromContent: Content -> string =
6467
function
@@ -171,6 +174,7 @@ module MqClient =
171174
fun config exCallback connection ->
172175
try
173176
let model = connection.CreateModel()
177+
model.BasicQos(uint32 0, config.prefetchCount,false)
174178

175179
if config.withConfirmSelect then model.ConfirmSelect()
176180

@@ -306,18 +310,23 @@ module MqClient =
306310

307311
let messageId: ReceivedMessage -> string = fun (Message(event, _)) -> event.BasicProperties.MessageId
308312

309-
let init: LogError -> string -> System.Uri -> (Model -> Topology) -> Result<Model, string> =
310-
fun logError nameOfClient uri getTopology ->
313+
let init: LogError -> string -> System.Uri -> Option<PrefetchCount> -> (Model -> Topology) -> Result<Model, string> =
314+
fun logError nameOfClient uri prefetchCountOption getTopology ->
315+
let prefetchCount =
316+
prefetchCountOption
317+
|> Option.map (fun (PrefetchCount prefetchCount) -> prefetchCount)
318+
|> Option.defaultValue (uint16 10)
319+
311320
connect nameOfClient uri
312321
|> Result.bind (fun connection ->
313322
let exCallback =
314323
(fun ex context connection ->
315324
logError (ex, "Unhandled exception on channel in context {$c}", context)
316325
closeConnectionAsync (System.TimeSpan.FromSeconds 3.0) connection)
317326

318-
createChannel { withConfirmSelect = true } exCallback connection
327+
createChannel { withConfirmSelect = true; prefetchCount = prefetchCount } exCallback connection
319328
|> Result.bind (fun channel ->
320-
createChannel { withConfirmSelect = false } exCallback connection
329+
createChannel { withConfirmSelect = false; prefetchCount = prefetchCount } exCallback connection
321330
|> Result.map (fun rpcChannel ->
322331
Model
323332
{ channelConsumer = AsyncEventingBasicConsumer channel

0 commit comments

Comments
 (0)