Skip to content

Commit 6b4a72d

Browse files
authored
Add NServiceBus 10 version to the Bridge snippets (#7720)
* Add NServiceBus 10 version to the Bridge snippets * Add prerelease file
1 parent 046d325 commit 6b4a72d

File tree

7 files changed

+328
-0
lines changed

7 files changed

+328
-0
lines changed

Snippets/Bridge/Bridge.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bridge_3.1", "Bridge_3.1\Br
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bridge_4", "Bridge_4\Bridge_4.csproj", "{E61A61FA-2554-4B7E-826D-180273707999}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bridge_5", "Bridge_5\Bridge_5.csproj", "{1731BD00-483A-4EC0-84DB-184772F1C1FC}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
4547
{E61A61FA-2554-4B7E-826D-180273707999}.Debug|Any CPU.Build.0 = Debug|Any CPU
4648
{E61A61FA-2554-4B7E-826D-180273707999}.Release|Any CPU.ActiveCfg = Release|Any CPU
4749
{E61A61FA-2554-4B7E-826D-180273707999}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{1731BD00-483A-4EC0-84DB-184772F1C1FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{1731BD00-483A-4EC0-84DB-184772F1C1FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{1731BD00-483A-4EC0-84DB-184772F1C1FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{1731BD00-483A-4EC0-84DB-184772F1C1FC}.Release|Any CPU.Build.0 = Release|Any CPU
4854
EndGlobalSection
4955
GlobalSection(SolutionProperties) = preSolution
5056
HideSolutionNode = FALSE

Snippets/Bridge/Bridge_5/API.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NServiceBus;
2+
3+
public class API
4+
{
5+
public void Configuration()
6+
{
7+
var connectionString = string.Empty;
8+
9+
#region bridgeconfiguration
10+
11+
var bridgeConfiguration = new BridgeConfiguration();
12+
13+
var msmq = new BridgeTransport(new MsmqTransport());
14+
var asb = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default));
15+
16+
msmq.HasEndpoint("Sales");
17+
asb.HasEndpoint("Billing");
18+
19+
bridgeConfiguration.AddTransport(msmq);
20+
bridgeConfiguration.AddTransport(asb);
21+
22+
#endregion
23+
}
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0-windows</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="NServiceBus.MessagingBridge" Version="5.0.0-alpha.1" />
7+
<PackageReference Include="NServiceBus.MessagingBridge.Msmq" Version="5.0.0-alpha.1" />
8+
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="6.0.0-alpha.1" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
using Messages;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using NServiceBus;
5+
using System;
6+
using System.Threading.Tasks;
7+
8+
public class Configuration
9+
{
10+
public async Task GenericHost()
11+
{
12+
#region generic-host
13+
14+
await Host.CreateDefaultBuilder()
15+
.UseNServiceBusBridge(bridgeConfiguration =>
16+
{
17+
// Configure the bridge
18+
})
19+
.Build()
20+
.RunAsync();
21+
22+
#endregion
23+
}
24+
25+
public async Task GenericHostBuilderContext()
26+
{
27+
#region generic-host-builder-context
28+
29+
await Host.CreateDefaultBuilder()
30+
.UseNServiceBusBridge((hostBuilderContext, bridgeConfiguration) =>
31+
{
32+
var connectionString = hostBuilderContext.Configuration.GetValue<string>("MyBridge:AzureServiceBusConnectionString");
33+
var concurrency = hostBuilderContext.Configuration.GetValue<int>("MyBridge:Concurrency");
34+
35+
var transport = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default))
36+
{
37+
Concurrency = concurrency
38+
};
39+
40+
bridgeConfiguration.AddTransport(transport);
41+
42+
// more configuration...
43+
})
44+
.Build()
45+
.RunAsync();
46+
47+
#endregion
48+
}
49+
50+
public async Task EndpointRegistration()
51+
{
52+
#region endpoint-registration
53+
54+
await Host.CreateDefaultBuilder()
55+
.UseNServiceBusBridge((ctx, bridgeConfiguration) =>
56+
{
57+
var msmq = new BridgeTransport(new MsmqTransport());
58+
msmq.HasEndpoint("Sales");
59+
msmq.HasEndpoint("Shipping");
60+
61+
var asb = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default));
62+
asb.HasEndpoint("Finance.Invoicing");
63+
asb.HasEndpoint("Finance.Billing");
64+
65+
bridgeConfiguration.AddTransport(msmq);
66+
bridgeConfiguration.AddTransport(asb);
67+
})
68+
.Build()
69+
.RunAsync();
70+
71+
#endregion
72+
}
73+
74+
public void RegisterPublishers()
75+
{
76+
#region register-publisher
77+
78+
var msmq = new BridgeTransport(new MsmqTransport());
79+
msmq.HasEndpoint("Sales");
80+
msmq.HasEndpoint("Finance.Billing");
81+
82+
var asb = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default));
83+
asb.HasEndpoint("Shipping");
84+
85+
var invoicing = new BridgeEndpoint("Finance.Invoicing");
86+
invoicing.RegisterPublisher(typeof(OrderBilled), "Finance.Billing");
87+
invoicing.RegisterPublisher<OrderShipped>("Shipping");
88+
invoicing.RegisterPublisher("Messages.OrderPlaced", "Sales");
89+
90+
asb.HasEndpoint(invoicing);
91+
92+
#endregion
93+
94+
#region register-publisher-legacy
95+
96+
// Type.AssemblyQualifiedName Property value
97+
invoicing.RegisterPublisher("CreditApproved, CreditScoring.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Sales");
98+
// Type.AssemblyQualifiedName Property but trimmed without Culture and PublicKeyToken as these are ignored by the message driven pub/sub feature
99+
invoicing.RegisterPublisher("CreditApproved, CreditScoring.Messages, Version=1.0.0.0", "Sales");
100+
101+
102+
#endregion
103+
}
104+
105+
public void AutoCreateQueues()
106+
{
107+
#region auto-create-queues
108+
109+
var msmq = new BridgeTransport(new MsmqTransport())
110+
{
111+
AutoCreateQueues = true
112+
};
113+
114+
var azureServiceBus = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default))
115+
{
116+
AutoCreateQueues = true
117+
};
118+
119+
#endregion
120+
121+
#region auto-create-queues-proxies
122+
123+
msmq.HasEndpoint("Sales");
124+
azureServiceBus.HasEndpoint("Billing");
125+
126+
#endregion
127+
}
128+
129+
public void CustomConcurrency()
130+
{
131+
#region custom-concurrency
132+
133+
var msmq = new BridgeTransport(new MsmqTransport())
134+
{
135+
Concurrency = 10
136+
};
137+
138+
var azureServiceBus = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default))
139+
{
140+
Concurrency = 5
141+
};
142+
143+
#endregion
144+
}
145+
146+
public void CustomErrorQueue()
147+
{
148+
#region custom-error-queue
149+
150+
var msmq = new BridgeTransport(new MsmqTransport())
151+
{
152+
ErrorQueue = "my-msmq-bridge-error-queue"
153+
};
154+
155+
var azureServiceBus = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default))
156+
{
157+
ErrorQueue = "my-asb-bridge-error-queue"
158+
};
159+
160+
#endregion
161+
}
162+
163+
public void CustomTransportName()
164+
{
165+
#region custom-transport-name
166+
167+
var azureServiceBus1 = new BridgeTransport(new AzureServiceBusTransport(connectionStringNamepace1, TopicTopology.Default))
168+
{
169+
Name = "asb-namespace-1"
170+
};
171+
172+
var azureServiceBus2 = new BridgeTransport(new AzureServiceBusTransport(connectionStringNamepace2, TopicTopology.Default))
173+
{
174+
Name = "asb-namespace-2"
175+
};
176+
177+
#endregion
178+
}
179+
180+
public void PlatformBridging()
181+
{
182+
#region platform-bridging
183+
184+
var transportWhereServiceControlIsInstalled = new BridgeTransport(new MsmqTransport());
185+
186+
transportWhereServiceControlIsInstalled.HasEndpoint("Particular.ServiceControl");
187+
transportWhereServiceControlIsInstalled.HasEndpoint("Particular.Monitoring");
188+
transportWhereServiceControlIsInstalled.HasEndpoint("error");
189+
transportWhereServiceControlIsInstalled.HasEndpoint("audit");
190+
191+
#endregion
192+
}
193+
194+
public void QueueName()
195+
{
196+
#region custom-address
197+
198+
var transport = new BridgeTransport(new MsmqTransport());
199+
transport.HasEndpoint("Finance", "finance@machinename");
200+
201+
var endpoint = new BridgeEndpoint("Sales", "sales@another-machine");
202+
transport.HasEndpoint(endpoint);
203+
204+
#endregion
205+
}
206+
207+
public void DoNotEnforceBestPractices()
208+
{
209+
var bridgeConfiguration = new BridgeConfiguration();
210+
211+
#region do-not-enforce-best-practices
212+
213+
bridgeConfiguration.DoNotEnforceBestPractices();
214+
215+
#endregion
216+
}
217+
218+
public void ConfigureHeartbeats()
219+
{
220+
var bridgeTransport = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default));
221+
222+
#region configure-heartbeats
223+
224+
bridgeTransport.SendHeartbeatTo(
225+
serviceControlQueue: "ServiceControl_Queue",
226+
frequency: TimeSpan.FromSeconds(15),
227+
timeToLive: TimeSpan.FromSeconds(30));
228+
229+
#endregion
230+
}
231+
232+
public void ConfigureCustomChecks()
233+
{
234+
var bridgeTransport = new BridgeTransport(new AzureServiceBusTransport(connectionString, TopicTopology.Default));
235+
236+
#region configure-custom-checks
237+
238+
bridgeTransport.ReportCustomChecksTo(
239+
serviceControlQueue: "ServiceControl_Queue",
240+
timeToLive: TimeSpan.FromSeconds(30));
241+
242+
#endregion
243+
}
244+
245+
public void DoNotTranslateReplyToAddressForFailedMessages()
246+
{
247+
var bridgeConfiguration = new BridgeConfiguration();
248+
249+
#region do-not-translate-reply-to-address-for-failed-messages
250+
251+
bridgeConfiguration.DoNotTranslateReplyToAddressForFailedMessages();
252+
253+
#endregion
254+
}
255+
256+
string connectionString = string.Empty;
257+
string connectionStringNamepace1 = string.Empty;
258+
string connectionStringNamepace2 = string.Empty;
259+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using NServiceBus;
2+
3+
class ConfigureTransactionMode
4+
{
5+
void SetExplicitReceiveOnly()
6+
{
7+
#region bridge-configuration-explicit-receive-only-mode
8+
9+
var bridgeConfiguration = new BridgeConfiguration();
10+
11+
bridgeConfiguration.RunInReceiveOnlyTransactionMode();
12+
13+
#endregion
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Messages
2+
{
3+
public class OrderPlaced
4+
{
5+
}
6+
7+
public class OrderBilled
8+
{
9+
}
10+
11+
public class OrderShipped
12+
{
13+
}
14+
}

Snippets/Bridge/Bridge_5/prerelease.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)