Skip to content

Commit ca3716b

Browse files
feat: service bus migration (#1148)
* feat: migrate to service bus * feat: service bus migration * feat: new functions * feat: distribute participant * feat: queue name switch * revert changes * fix: update name * Update Program.cs * fix: tests * fix: tests * fix: sonarqube issues * fix: adding the use UseNewFunctions to tf vars * chore: exention does not now use any input params * fix: calling the FetchDataActivity in the DistributeParticipant function code * chore: addressing comments * chore: addressing comments --------- Co-authored-by: SamRobinson75684 <[email protected]> Co-authored-by: SamRobinson75684 <[email protected]>
1 parent 96677c5 commit ca3716b

File tree

40 files changed

+542
-116
lines changed

40 files changed

+542
-116
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"UserConfig": {
3+
"Namespaces": [
4+
{
5+
"Name": "cohman-sb",
6+
"Queues": [
7+
{
8+
"Name": "participant-management-queue",
9+
"Properties": {
10+
"DeadLetteringOnMessageExpiration": false,
11+
"DefaultMessageTimeToLive": "PT1H",
12+
"DuplicateDetectionHistoryTimeWindow": "PT20S",
13+
"ForwardDeadLetteredMessagesTo": "",
14+
"ForwardTo": "",
15+
"LockDuration": "PT1M",
16+
"MaxDeliveryCount": 3,
17+
"RequiresDuplicateDetection": false,
18+
"RequiresSession": false
19+
}
20+
},
21+
{
22+
"Name": "cohort-distribution-queue",
23+
"Properties": {
24+
"DeadLetteringOnMessageExpiration": false,
25+
"DefaultMessageTimeToLive": "PT1H",
26+
"DuplicateDetectionHistoryTimeWindow": "PT20S",
27+
"ForwardDeadLetteredMessagesTo": "",
28+
"ForwardTo": "",
29+
"LockDuration": "PT1M",
30+
"MaxDeliveryCount": 3,
31+
"RequiresDuplicateDetection": false,
32+
"RequiresSession": false
33+
}
34+
}
35+
]
36+
}
37+
],
38+
"Logging": {
39+
"Type": "File"
40+
}
41+
}
42+
}

application/CohortManager/compose.cohort-distribution.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
name: cohort-manager
22

33
services:
4+
distribute-participant:
5+
container_name: distribute-participant
6+
image: cohort-manager-distribute-participant
7+
networks: [cohman-network]
8+
build:
9+
context: ./src/Functions/
10+
dockerfile: CohortDistributionServices/DistributeParticipant/Dockerfile
11+
environment:
12+
- ServiceBusConnectionString=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;
13+
- CohortQueueName=cohort-distribution-queue
14+
- AzureWebJobsStorage=${AZURITE_CONNECTION_STRING}
15+
- WEBSITE_HOSTNAME=localhost:8080
16+
17+
418
retrieve-cohort-distribution-data:
519
container_name: retrieve-cohort-distribution-data
620
image: cohort-manager-retrieve-cohort-distribution-data

application/CohortManager/compose.core.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: cohort-manager
22

33
services:
44
# CaaS Integration Service
5-
65
retrieve-mesh-file:
76
container_name: retrieve-mesh-file
87
image: cohort-manager-retrieve-mesh-file
@@ -86,9 +85,24 @@ services:
8685
- ScreeningLkpDataServiceURL=http://screening-lkp-data-service:8996/api/ScreeningLkpDataService
8786
- maxNumberOfChecks=50
8887
- inboundBlobName=inbound
88+
- ServiceBusConnectionString=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;
8989
- fileExceptions=file-exceptions
90+
- ParticipantManagementQueueName=participant-management-queue
91+
- UseNewFunctions=false
9092

9193
# Participant Management Service
94+
manage-participant:
95+
container_name: manage-participant
96+
image: cohort-manager-manage-participant
97+
networks: [cohman-network]
98+
build:
99+
context: ./src/Functions/
100+
dockerfile: ParticipantManagementServices/ManageParticipant/Dockerfile
101+
environment:
102+
- ServiceBusConnectionString=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;
103+
- CohortQueueName=cohort-distribution-queue
104+
- ParticipantManagementQueueName=participant-management-queue
105+
92106
add-participant:
93107
container_name: add-participant
94108
image: cohort-manager-add-participant

application/CohortManager/compose.deps.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ services:
2323
environment:
2424
- AZURITE_CONNECTION_STRING=${AZURITE_CONNECTION_STRING}
2525

26+
service-bus:
27+
container_name: service-bus
28+
networks: [cohman-network]
29+
image: mcr.microsoft.com/azure-messaging/servicebus-emulator:latest
30+
volumes:
31+
- "./Set-up/service-bus/config.json:/ServiceBus_Emulator/ConfigFiles/Config.json"
32+
ports:
33+
- "5672:5672"
34+
- "5300:5300"
35+
environment:
36+
- ACCEPT_EULA=Y
37+
- SQL_SERVER=db
38+
- MSSQL_SA_PASSWORD=${PASSWORD}
39+
- SQL_WAIT_INTERVAL=20
40+
depends_on:
41+
- db
42+
2643
db:
2744
container_name: db
2845
networks: [cohman-network]

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/ProcessFileClasses/AddBatchToQueue.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ namespace NHS.Screening.ReceiveCaasFile;
1111
public class AddBatchToQueue : IAddBatchToQueue
1212
{
1313

14-
public readonly ILogger<AddBatchToQueue> _logger;
14+
private readonly ILogger<AddBatchToQueue> _logger;
15+
private readonly IQueueClient _queueClient;
1516

16-
17-
private readonly IAzureQueueStorageHelper _queueHelper;
18-
19-
public AddBatchToQueue(ILogger<AddBatchToQueue> logger, IAzureQueueStorageHelper queueHelper)
17+
public AddBatchToQueue(ILogger<AddBatchToQueue> logger, IQueueClient queueClient)
2018
{
2119
_logger = logger;
22-
_queueHelper = queueHelper;
20+
_queueClient = queueClient;
2321
}
2422

2523
public async Task ProcessBatch(ConcurrentQueue<BasicParticipantCsvRecord> batch, string queueName)
@@ -52,6 +50,6 @@ private async Task AddMessagesAsync(ConcurrentQueue<BasicParticipantCsvRecord> c
5250

5351
private async Task AddMessage(BasicParticipantCsvRecord basicParticipantCsvRecord, string queueName)
5452
{
55-
await _queueHelper.AddItemToQueueAsync<BasicParticipantCsvRecord>(basicParticipantCsvRecord, queueName);
53+
await _queueClient.AddAsync<BasicParticipantCsvRecord>(basicParticipantCsvRecord, queueName);
5654
}
5755
}

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/ProcessFileClasses/ProcessCaasFile.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@ IOptions<ReceiveCaasFileConfig> receiveCaasFileConfig
5656
_config = receiveCaasFileConfig.Value;
5757
_httpClientFunction = httpClientFactory;
5858
DemographicURI = _config.DemographicURI;
59-
AddParticipantQueueName = _config.AddQueueName;
60-
UpdateParticipantQueueName = _config.UpdateQueueName;
59+
if (_config.UseNewFunctions)
60+
{
61+
AddParticipantQueueName = _config.ParticipantManagementQueueName;
62+
UpdateParticipantQueueName = _config.ParticipantManagementQueueName;
63+
}
64+
else
65+
{
66+
AddParticipantQueueName = _config.AddQueueName;
67+
UpdateParticipantQueueName = _config.UpdateQueueName;
68+
}
6169

6270

6371
if (string.IsNullOrEmpty(DemographicURI) || string.IsNullOrEmpty(AddParticipantQueueName) || string.IsNullOrEmpty(UpdateParticipantQueueName))

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
services.AddTransient<IExceptionHandler, ExceptionHandler>();
3939
services.AddTransient<IBlobStorageHelper, BlobStorageHelper>();
4040
services.AddTransient<ICopyFailedBatchToBlob, CopyFailedBatchToBlob>();
41-
4241
services.AddScoped<IValidateDates, ValidateDates>();
43-
services.AddScoped<IQueueClientFactory, QueueClientFactory>();
4442
// Register health checks
4543
services.AddBlobStorageHealthCheck("receiveCaasFile");
4644
})

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/receiveCaasFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace NHS.Screening.ReceiveCaasFile;
88
using ParquetSharp.RowOriented;
99
using System.Threading.Tasks;
1010
using Common;
11-
using Common.Interfaces;
1211
using DataServices.Client;
1312
using Microsoft.Extensions.Options;
1413

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/receiveCaasFile.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Nullable>enable</Nullable>
99
</PropertyGroup>
1010
<ItemGroup>
11+
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.20.1" />
1112
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
1213
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
1314
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.7.0" />

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/receiveCaasFileConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ public class ReceiveCaasFileConfig
2525
public string caasfolder_STORAGE { get; set; }
2626
[Required]
2727
public string inboundBlobName { get; set; }
28+
[Required]
29+
public string ServiceBusConnectionString { get; set; }
2830
public string GetOrchestrationStatusURL { get; set; }
31+
public bool UseNewFunctions { get; set; } = false;
32+
public string ParticipantManagementQueueName {get; set;}
2933
}

0 commit comments

Comments
 (0)