Skip to content

Commit b617f57

Browse files
committed
Made the endpoint name configurable for the job service instance endpoint.
1 parent 9337e4d commit b617f57

3 files changed

Lines changed: 23 additions & 24 deletions

File tree

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1+
#nullable enable
12
namespace MassTransit.Configuration
23
{
3-
using System.Text;
44
using JobService;
5-
using NewIdFormatters;
65

76

87
public class JobServiceEndpointDefinition :
98
IEndpointDefinition<JobService>
109
{
1110
readonly InstanceJobServiceSettings _jobServiceSettings;
1211
readonly IEndpointSettings<IEndpointDefinition<JobService>> _settings;
12+
string? _endpointName;
1313

1414
public JobServiceEndpointDefinition(IEndpointSettings<IEndpointDefinition<JobService>> settings, InstanceJobServiceSettings jobServiceSettings)
1515
{
1616
_settings = settings;
1717
_jobServiceSettings = jobServiceSettings;
18-
19-
var instanceId = NewId.Next();
20-
21-
InstanceName = instanceId.ToString(ZBase32Formatter.LowerCase);
2218
}
2319

24-
string InstanceName { get; }
25-
2620
public bool IsTemporary => true;
2721
public int? PrefetchCount => _settings.PrefetchCount;
2822
public int? ConcurrentMessageLimit => _settings.ConcurrentMessageLimit;
2923
public bool ConfigureConsumeTopology => _settings.ConfigureConsumeTopology;
3024

31-
public void Configure<T>(T configurator, IRegistrationContext context)
25+
public void Configure<T>(T configurator, IRegistrationContext? context)
3226
where T : IReceiveEndpointConfigurator
3327
{
3428
_jobServiceSettings.ApplyConfiguration(configurator);
@@ -38,13 +32,14 @@ public void Configure<T>(T configurator, IRegistrationContext context)
3832

3933
public string GetEndpointName(IEndpointNameFormatter formatter)
4034
{
41-
var sb = new StringBuilder(InstanceName.Length + 9);
42-
43-
sb.Append("Instance");
44-
sb.Append('_');
45-
sb.Append(InstanceName);
46-
47-
return formatter.SanitizeName(sb.ToString());
35+
string FormatName()
36+
{
37+
return _settings.Name ?? "Instance";
38+
}
39+
40+
return _endpointName ??= string.IsNullOrWhiteSpace(_settings.InstanceId)
41+
? formatter.SanitizeName(FormatName())
42+
: formatter.SanitizeName(FormatName() + formatter.Separator + _settings.InstanceId);
4843
}
4944
}
5045
}

src/MassTransit/DependencyInjection/DependencyInjection/Registration/Activites/JobServiceRegistration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public JobServiceRegistration()
2525

2626
_endpointConfigurator = new EndpointRegistrationConfigurator<JobService>
2727
{
28+
Name = "Instance",
2829
InstanceId = NewId.Next().ToString(ZBase32Formatter.LowerCase),
2930
Temporary = true
3031
};

tests/MassTransit.Azure.ServiceBus.Core.Tests/JobConsumer_Specs.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace MassTransit.Azure.ServiceBus.Core.Tests
33
using System;
44
using System.Threading.Tasks;
55
using Contracts.JobService;
6-
using global::Azure;
76
using JobConsumerTests;
87
using Microsoft.Extensions.DependencyInjection;
98
using NUnit.Framework;
@@ -59,7 +58,7 @@ public async Task Should_cancel_the_job()
5958

6059
IRequestClient<SubmitJob<OddJob>> client = harness.GetRequestClient<SubmitJob<OddJob>>();
6160

62-
MassTransit.Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
61+
Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
6362
{
6463
JobId = jobId,
6564
Job = new { Duration = TimeSpan.FromSeconds(10) }
@@ -93,7 +92,7 @@ public async Task Should_cancel_the_job_and_get_the_status()
9392

9493
IRequestClient<SubmitJob<OddJob>> client = harness.GetRequestClient<SubmitJob<OddJob>>();
9594

96-
MassTransit.Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
95+
Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
9796
{
9897
JobId = jobId,
9998
Job = new { Duration = TimeSpan.FromSeconds(10) }
@@ -111,7 +110,7 @@ await Assert.MultipleAsync(async () =>
111110

112111
IRequestClient<GetJobState> stateClient = harness.GetRequestClient<GetJobState>();
113112

114-
MassTransit.Response<JobState> jobState = await stateClient.GetResponse<JobState>(new { JobId = jobId });
113+
Response<JobState> jobState = await stateClient.GetResponse<JobState>(new { JobId = jobId });
115114

116115
Assert.That(jobState.Message.CurrentState, Is.EqualTo("Started"));
117116

@@ -141,7 +140,7 @@ public async Task Should_cancel_the_job_and_retry_it()
141140

142141
IRequestClient<SubmitJob<OddJob>> client = harness.GetRequestClient<SubmitJob<OddJob>>();
143142

144-
MassTransit.Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
143+
Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
145144
{
146145
JobId = jobId,
147146
Job = new { Duration = TimeSpan.FromSeconds(10) }
@@ -188,7 +187,7 @@ public async Task Should_cancel_the_job_while_waiting()
188187

189188
IRequestClient<SubmitJob<OddJob>> client = harness.GetRequestClient<SubmitJob<OddJob>>();
190189

191-
MassTransit.Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
190+
Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
192191
{
193192
JobId = previousJobId,
194193
Job = new { Duration = TimeSpan.FromSeconds(10) }
@@ -232,7 +231,7 @@ public async Task Should_complete_the_job()
232231

233232
IRequestClient<SubmitJob<OddJob>> client = harness.GetRequestClient<SubmitJob<OddJob>>();
234233

235-
MassTransit.Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
234+
Response<JobSubmissionAccepted> response = await client.GetResponse<JobSubmissionAccepted>(new
236235
{
237236
JobId = jobId,
238237
Job = new { Duration = TimeSpan.FromSeconds(1) }
@@ -314,7 +313,11 @@ static ServiceProvider SetupServiceCollection()
314313

315314
x.AddJobSagaStateMachines();
316315
x.SetJobConsumerOptions(options => options.HeartbeatInterval = TimeSpan.FromSeconds(10))
317-
.Endpoint(e => e.PrefetchCount = 100);
316+
.Endpoint(e =>
317+
{
318+
e.Name = "Prefix-Instance";
319+
e.PrefetchCount = 100;
320+
});
318321

319322
x.UsingTestAzureServiceBus();
320323
})

0 commit comments

Comments
 (0)