Skip to content

Commit ce028bd

Browse files
authored
File-share-databus sample - add MS extension hosting in receiver endpoint (#7562)
In order to add back usage of structured logging in the message handler, just like DataBus_1. Amend to #7512
1 parent a8197d7 commit ce028bd

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
using System.Threading.Tasks;
2-
using NServiceBus;
3-
using NServiceBus.Logging;
4-
1+
using Microsoft.Extensions.Logging;
52
#region MessageWithLargePayloadHandler
63

7-
public class MessageWithLargePayloadHandler :
4+
public class MessageWithLargePayloadHandler(ILogger<MessageWithLargePayloadHandler> logger) :
85
IHandleMessages<MessageWithLargePayload>
96
{
10-
static ILog log = LogManager.GetLogger<MessageWithLargePayloadHandler>();
117

128
public Task Handle(MessageWithLargePayload message, IMessageHandlerContext context)
139
{
14-
log.Info($"Message received, size of blob property: {message.LargeBlob.Value.Length} Bytes");
10+
logger.LogInformation("Message received, size of blob property: {BlobSize} Bytes", message.LargeBlob.Value.Length);
1511
return Task.CompletedTask;
1612
}
1713
}
1814

19-
#endregion
15+
#endregion
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Shared;
2+
using Microsoft.Extensions.Hosting;
23

34
Console.Title = "Receiver";
45

6+
var builder = Host.CreateApplicationBuilder(args);
7+
58
var endpointConfiguration = new EndpointConfiguration("Samples.ClaimCheck.Receiver");
69
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
710
endpointConfiguration.UseTransport(new LearningTransport());
@@ -10,9 +13,13 @@
1013
var storagePath = new SolutionDirectoryFinder().GetDirectory("storage");
1114
claimCheck.BasePath(storagePath);
1215

13-
var endpointInstance = await Endpoint.Start(endpointConfiguration);
16+
builder.UseNServiceBus(endpointConfiguration);
17+
18+
var host = builder.Build();
19+
await host.StartAsync();
1420

1521
Console.WriteLine("Press any key to exit");
1622
Console.ReadKey();
1723

18-
await endpointInstance.Stop();
24+
await host.StopAsync();
25+

samples/databus/file-share-databus/DataBus_2/Receiver/Receiver.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<PackageReference Include="NServiceBus.ClaimCheck" Version="2.0.0-alpha.1" />
10+
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="4.0.0-alpha.1" />
1011
<ProjectReference Include="..\Shared\Shared.csproj" />
1112
</ItemGroup>
1213
</Project>

0 commit comments

Comments
 (0)