Skip to content

Commit 30e179b

Browse files
Release/v5.2.0 (#88)
* Introduced SendDispatch methods on DispatchSender * Changed version to 5.2.0
1 parent 7ff8392 commit 30e179b

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and 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

src/Ev.ServiceBus.Abstractions/IDispatchSender.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ namespace Ev.ServiceBus.Abstractions;
77

88
public 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"/>)

src/Ev.ServiceBus/Dispatch/DispatchSender.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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
{

tests/Ev.ServiceBus.UnitTests/DispatchTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)