File tree Expand file tree Collapse file tree
Ev.ServiceBus.Abstractions
tests/Ev.ServiceBus.UnitTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33
44The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
55and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6+ ## 5.2.0
7+ - Added
8+ - Introduced SendDispatch methods on DispatchSender. Those methods allow to send single message bigger than 1MB
9+
610## 5.1.5
711- Changed
812 - skip transaction renaming when ServiceBus instrumentation is missing
Original file line number Diff line number Diff line change @@ -7,6 +7,24 @@ namespace Ev.ServiceBus.Abstractions;
77
88public interface IDispatchSender
99{
10+ /// <summary>
11+ /// Immediately serializes object to message and sends it through ServiceBus.
12+ /// Single message on Premium tier can be bigger than 1MB.
13+ /// </summary>
14+ /// <param name="messagePayload"></param>
15+ /// <param name="token"></param>
16+ /// <returns></returns>
17+ Task SendDispatch ( object messagePayload , CancellationToken token = default ) ;
18+
19+ /// <summary>
20+ /// Immediately serializes object to message and sends it through ServiceBus.
21+ /// Single message on Premium tier can be bigger than 1MB.
22+ /// </summary>
23+ /// <param name="messagePayload"></param>
24+ /// <param name="token"></param>
25+ /// <returns></returns>
26+ Task SendDispatch ( Dispatch messagePayload , CancellationToken token = default ) ;
27+
1028 /// <summary>
1129 /// Immediately serializes object to messages and sends them through ServiceBus.
1230 /// (This is used internally by <see cref="IMessageDispatcher.ExecuteDispatches"/>)
Original file line number Diff line number Diff line change @@ -34,6 +34,27 @@ public DispatchSender(
3434 _dispatchCustomizers = dispatchCustomizers ;
3535 }
3636
37+ /// <inheritdoc />
38+ public async Task SendDispatch ( object messagePayload , CancellationToken token = default )
39+ {
40+ var dispatch = new Abstractions . Dispatch ( messagePayload ) ;
41+
42+ await SendDispatch ( dispatch , token ) ;
43+ }
44+
45+ /// <inheritdoc />
46+ public async Task SendDispatch ( Abstractions . Dispatch messagePayload , CancellationToken token = default )
47+ {
48+ var dispatches = CreateMessagesToSend ( [ messagePayload ] ) ;
49+
50+ foreach ( var messagePerResource in dispatches )
51+ {
52+ var message = messagePerResource . Messages . Single ( ) ;
53+
54+ await messagePerResource . Sender . SendMessageAsync ( message . Message , token ) ;
55+ }
56+ }
57+
3758 /// <inheritdoc />
3859 public async Task SendDispatches ( IEnumerable < object > messagePayloads , CancellationToken token = default )
3960 {
Original file line number Diff line number Diff line change @@ -396,6 +396,45 @@ await Assert.ThrowsAsync<ArgumentNullException>(
396396 }
397397 }
398398
399+ [ Fact ]
400+ public async Task SendDispatch ( )
401+ {
402+ // configure
403+ var services = new ServiceCollection ( ) ;
404+ services . AddServiceBus ( settings =>
405+ {
406+ settings . WithConnection ( "myConnection" , new ServiceBusClientOptions ( ) ) ;
407+ } ) ;
408+ services . OverrideClientFactory ( ) ;
409+ services . RegisterServiceBusDispatch ( ) . ToQueue ( "myQueue" , builder =>
410+ {
411+ builder . RegisterDispatch < SubscribedEvent > ( ) ;
412+ } ) ;
413+ var provider = services . BuildServiceProvider ( ) ;
414+ await provider . SimulateStartHost ( CancellationToken . None ) ;
415+
416+ // Act
417+ var message = new SubscribedEvent
418+ {
419+ SomeNumber = 1 ,
420+ SomeString = "Event number 1"
421+ } ;
422+
423+ using ( var scope = provider . CreateScope ( ) )
424+ {
425+ var eventPublisher = scope . ServiceProvider . GetRequiredService < IDispatchSender > ( ) ;
426+ await eventPublisher . SendDispatch ( message ) ;
427+ }
428+
429+ // Verify
430+ var factory = provider . GetRequiredService < FakeClientFactory > ( ) ;
431+ var mock = factory . GetSenderMock ( "myQueue" ) ;
432+ mock . Mock . Verify ( o => o . SendMessageAsync ( It . IsAny < ServiceBusMessage > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
433+
434+ // Dispose
435+ await provider . SimulateStopHost ( CancellationToken . None ) ;
436+ }
437+
399438 [ Fact ]
400439 public async Task SendDispatchesPaginateMessages ( )
401440 {
You can’t perform that action at this time.
0 commit comments