From b4dccbf77493774668c5f616b7d3e43ead2178de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Tom=C3=A1s?= Date: Thu, 17 Aug 2017 13:00:48 +0200 Subject: [PATCH] Fix bug service bus not receiving messages Update service bus to 1.0 version --- .../EventBusServiceBus/EventBusServiceBus.cs | 35 +++++++++++++------ .../EventBusServiceBus.csproj | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs index 50f588ac3..1458b7198 100644 --- a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs @@ -1,18 +1,17 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus { - using System; + using Autofac; + using Microsoft.Azure.ServiceBus; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; using Microsoft.Extensions.Logging; - using Microsoft.Azure.ServiceBus; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + using System; + using System.Reflection; using System.Text; using System.Threading.Tasks; - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; - using System.Reflection; - using Microsoft.Azure.ServiceBus.Filters; - using Autofac; - using Newtonsoft.Json.Linq; public class EventBusServiceBus : IEventBus { @@ -129,11 +128,25 @@ _subscriptionClient.RegisterMessageHandler( async (message, token) => { - var eventName = message.Label; + var eventName = $"{message.Label}{INTEGRATION_EVENT_SUFIX}"; var messageData = Encoding.UTF8.GetString(message.Body); await ProcessEvent(eventName, messageData); + + // Complete the message so that it is not received again. + await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); }, - new MessageHandlerOptions() { MaxConcurrentCalls = 10, AutoComplete = true }); + new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 10, AutoComplete = false }); + } + + private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs) + { + Console.WriteLine($"Message handler encountered an exception {exceptionReceivedEventArgs.Exception}."); + var context = exceptionReceivedEventArgs.ExceptionReceivedContext; + Console.WriteLine("Exception context for troubleshooting:"); + Console.WriteLine($"- Endpoint: {context.Endpoint}"); + Console.WriteLine($"- Entity Path: {context.EntityPath}"); + Console.WriteLine($"- Executing Action: {context.Action}"); + return Task.CompletedTask; } private async Task ProcessEvent(string eventName, string message) @@ -169,13 +182,13 @@ try { _subscriptionClient - .RemoveRuleAsync(SubscriptionClient.DefaultRule) + .RemoveRuleAsync(RuleDescription.DefaultRuleName) .GetAwaiter() .GetResult(); } catch (MessagingEntityNotFoundException) { - _logger.LogInformation($"The messaging entity {SubscriptionClient.DefaultRule} Could not be found."); + _logger.LogInformation($"The messaging entity { RuleDescription.DefaultRuleName } Could not be found."); } } } diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj index 5be30800e..b0d6f0cc2 100644 --- a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj @@ -6,7 +6,7 @@ - +