Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions PubSub.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 15.0.26730.12
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Subscriber", "Subscriber\Subscriber.csproj", "{2FE71442-7F81-428E-B945-D564850D6564}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Publisher", "Publisher\Publisher.csproj", "{11641841-C7E9-4B49-9688-99E54187A7E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{DD438DB2-9C03-4BC0-BA52-BB7A35098458}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2FE71442-7F81-428E-B945-D564850D6564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FE71442-7F81-428E-B945-D564850D6564}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11641841-C7E9-4B49-9688-99E54187A7E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11641841-C7E9-4B49-9688-99E54187A7E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD438DB2-9C03-4BC0-BA52-BB7A35098458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD438DB2-9C03-4BC0-BA52-BB7A35098458}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
64 changes: 64 additions & 0 deletions Publisher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Threading.Tasks;
using NServiceBus;

class Program
{
static async Task Main()
{
Console.Title = "Publisher";

#region config

var endpointConfiguration = new EndpointConfiguration("Samples.ASBS.PubSub.Publisher");
endpointConfiguration.EnableInstallers();

var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString");
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites.");
}

var storageConnectionString = Environment.GetEnvironmentVariable("AzureStorage_ConnectionString");
if (string.IsNullOrWhiteSpace(storageConnectionString))
{
throw new Exception("Could not read the 'AzureStorage_ConnectionString' environment variable. Check the sample prerequisites.");
}

var transport = new AzureServiceBusTransport(connectionString);
endpointConfiguration.UseTransport(transport);
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

endpointConfiguration.UseDataBus<AzureDataBus, SystemJsonDataBusSerializer>();

var databus = endpointConfiguration.UseDataBus<AzureDataBus, SystemJsonDataBusSerializer>();
databus.ConnectionString(storageConnectionString);

#endregion

var endpointInstance = await Endpoint.Start(endpointConfiguration);
Console.WriteLine("Press 'enter' to publish an event");
Console.WriteLine("Press any other key to exit");

while (true)
{
var key = Console.ReadKey();
Console.WriteLine();

if (key.Key != ConsoleKey.Enter)
{
break;
}

var message = new SomeEvent
{
Property = "Hello from Publisher",
DataBusProperty = new DataBusProperty<string>("Large message from publisher")
};

await endpointInstance.Publish(message);
Console.WriteLine("Event published");
}
await endpointInstance.Stop();
}
}
13 changes: 13 additions & 0 deletions Publisher/Publisher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<OutputType>Exe</OutputType>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="3.*" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Shared/Shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus" Version="8.2.4" />
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="5.0.0" />
<PackageReference Include="NServiceBus.DataBus.BinarySerializer" Version="1.0.0" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Shared/SomeEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using NServiceBus;

public class SomeEvent : IEvent
{
public string Property { get; set; }
public DataBusProperty<string> DataBusProperty { get; set; }
}
48 changes: 48 additions & 0 deletions Subscriber/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Threading.Tasks;
using NServiceBus;
using NServiceBus.DataBus;

class Program
{
static async Task Main()
{
Console.Title = "Subscriber";

#region Endpoint Configuration

var endpointConfiguration = new EndpointConfiguration("Samples.ASBS.PubSub.Subscriber");
endpointConfiguration.EnableInstallers();

var transportConnectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString");
if (string.IsNullOrWhiteSpace(transportConnectionString))
{
throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites.");
}

var storageConnectionString = Environment.GetEnvironmentVariable("AzureStorage_ConnectionString");
if(string.IsNullOrWhiteSpace(storageConnectionString))
{
throw new Exception("Could not read the 'AzureStorage_ConnectionString' environment variable. Check the sample prerequisites.");
}

var transport = new AzureServiceBusTransport(transportConnectionString);
endpointConfiguration.UseTransport(transport);
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#endregion

#pragma warning disable CS0618 // Type or member is obsolete
var databus = endpointConfiguration.UseDataBus<AzureDataBus, BinaryFormatterDataBusSerializer>();
#pragma warning restore CS0618 // Type or member is obsolete
databus.AddDeserializer<SystemJsonDataBusSerializer>();
databus.ConnectionString(storageConnectionString);

var endpointInstance = await Endpoint.Start(endpointConfiguration);

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

await endpointInstance.Stop();
}
}
17 changes: 17 additions & 0 deletions Subscriber/SomeEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using NServiceBus;
using NServiceBus.Logging;

public class SomeEventHandler :
IHandleMessages<SomeEvent>
{
static ILog log = LogManager.GetLogger<SomeEventHandler>();

public Task Handle(SomeEvent message, IMessageHandlerContext context)
{
log.Info($"Received SomeEvent: {message.Property}");
log.Info($"DataBus content: {message.DataBusProperty.Value }");

return Task.CompletedTask;
}
}
13 changes: 13 additions & 0 deletions Subscriber/Subscriber.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<OutputType>Exe</OutputType>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="3.*" />
</ItemGroup>
</Project>