Skip to content

Commit 11a2f14

Browse files
Pass event Id as message Id
1 parent 1369f16 commit 11a2f14

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,28 @@ private async Task HandleSpecificDomainEvent(CustomerEmailReceiptRequestedEvent
203203

204204
TransactionAggregate transactionAggregate = await this.TransactionAggregateManager.GetAggregate(domainEvent.EstateId, domainEvent.TransactionId, cancellationToken);
205205

206-
var merchant = await this.EstateClient.GetMerchant(this.TokenResponse.AccessToken, domainEvent.EstateId, domainEvent.MerchantId, cancellationToken);
206+
MerchantResponse merchant = await this.EstateClient.GetMerchant(this.TokenResponse.AccessToken, domainEvent.EstateId, domainEvent.MerchantId, cancellationToken);
207207

208208
// Determine the body of the email
209209
String receiptMessage = await this.TransactionReceiptBuilder.GetEmailReceiptMessage(transactionAggregate.GetTransaction(), merchant, cancellationToken);
210210

211211
// Send the message
212-
await this.SendEmailMessage(this.TokenResponse.AccessToken, domainEvent.EstateId, "Transaction Successful", receiptMessage, domainEvent.CustomerEmailAddress, cancellationToken);
212+
await this.SendEmailMessage(this.TokenResponse.AccessToken, domainEvent.EventId, domainEvent.EstateId, "Transaction Successful", receiptMessage, domainEvent.CustomerEmailAddress, cancellationToken);
213213

214214
}
215215

216216
/// <summary>
217217
/// Sends the email message.
218218
/// </summary>
219219
/// <param name="accessToken">The access token.</param>
220+
/// <param name="messageId">The message identifier.</param>
220221
/// <param name="estateId">The estate identifier.</param>
221222
/// <param name="subject">The subject.</param>
222223
/// <param name="body">The body.</param>
223224
/// <param name="emailAddress">The email address.</param>
224225
/// <param name="cancellationToken">The cancellation token.</param>
225226
private async Task SendEmailMessage(String accessToken,
227+
Guid messageId,
226228
Guid estateId,
227229
String subject,
228230
String body,
@@ -231,6 +233,7 @@ private async Task SendEmailMessage(String accessToken,
231233
{
232234
SendEmailRequest sendEmailRequest = new SendEmailRequest
233235
{
236+
MessageId = messageId,
234237
Body = body,
235238
ConnectionIdentifier = estateId,
236239
FromAddress = "[email protected]", // TODO: lookup from config
@@ -244,7 +247,19 @@ private async Task SendEmailMessage(String accessToken,
244247

245248
// TODO: may decide to record the message Id againsts the Transaction Aggregate in future, but for now
246249
// we wont do this...
247-
await this.MessagingServiceClient.SendEmail(accessToken, sendEmailRequest, cancellationToken);
250+
try
251+
{
252+
await this.MessagingServiceClient.SendEmail(accessToken, sendEmailRequest, cancellationToken);
253+
}
254+
catch(Exception ex) when (ex.InnerException != null && ex.InnerException.GetType() == typeof(InvalidOperationException))
255+
{
256+
// Only bubble up if not a duplicate message
257+
if (ex.InnerException.Message.Contains("Cannot send a message to provider that has already been sent", StringComparison.InvariantCultureIgnoreCase) == false)
258+
{
259+
throw;
260+
}
261+
}
262+
248263
}
249264

250265
#endregion

TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="EstateManagement.Client" Version="1.0.2.2-build25" />
9-
<PackageReference Include="MessagingService.Client" Version="1.0.3-build28" />
9+
<PackageReference Include="MessagingService.Client" Version="1.0.3.1" />
1010
<PackageReference Include="SecurityService.Client" Version="1.0.0" />
1111
<PackageReference Include="Shared" Version="0.0.15.7" />
1212
<PackageReference Include="Shared.DomainDrivenDesign" Version="0.0.15.7" />

0 commit comments

Comments
 (0)