Skip to content

Commit b4dccbf

Browse files
committed
Fix bug service bus not receiving messages
Update service bus to 1.0 version
1 parent 4876dd5 commit b4dccbf

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
22
{
3-
using System;
3+
using Autofac;
4+
using Microsoft.Azure.ServiceBus;
5+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
46
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
57
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
68
using Microsoft.Extensions.Logging;
7-
using Microsoft.Azure.ServiceBus;
89
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Linq;
11+
using System;
12+
using System.Reflection;
913
using System.Text;
1014
using System.Threading.Tasks;
11-
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
12-
using System.Reflection;
13-
using Microsoft.Azure.ServiceBus.Filters;
14-
using Autofac;
15-
using Newtonsoft.Json.Linq;
1615

1716
public class EventBusServiceBus : IEventBus
1817
{
@@ -129,11 +128,25 @@ private void RegisterSubscriptionClientMessageHandler()
129128
_subscriptionClient.RegisterMessageHandler(
130129
async (message, token) =>
131130
{
132-
var eventName = message.Label;
131+
var eventName = $"{message.Label}{INTEGRATION_EVENT_SUFIX}";
133132
var messageData = Encoding.UTF8.GetString(message.Body);
134133
await ProcessEvent(eventName, messageData);
134+
135+
// Complete the message so that it is not received again.
136+
await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
135137
},
136-
new MessageHandlerOptions() { MaxConcurrentCalls = 10, AutoComplete = true });
138+
new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 10, AutoComplete = false });
139+
}
140+
141+
private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
142+
{
143+
Console.WriteLine($"Message handler encountered an exception {exceptionReceivedEventArgs.Exception}.");
144+
var context = exceptionReceivedEventArgs.ExceptionReceivedContext;
145+
Console.WriteLine("Exception context for troubleshooting:");
146+
Console.WriteLine($"- Endpoint: {context.Endpoint}");
147+
Console.WriteLine($"- Entity Path: {context.EntityPath}");
148+
Console.WriteLine($"- Executing Action: {context.Action}");
149+
return Task.CompletedTask;
137150
}
138151

139152
private async Task ProcessEvent(string eventName, string message)
@@ -169,13 +182,13 @@ private void RemoveDefaultRule()
169182
try
170183
{
171184
_subscriptionClient
172-
.RemoveRuleAsync(SubscriptionClient.DefaultRule)
185+
.RemoveRuleAsync(RuleDescription.DefaultRuleName)
173186
.GetAwaiter()
174187
.GetResult();
175188
}
176189
catch (MessagingEntityNotFoundException)
177190
{
178-
_logger.LogInformation($"The messaging entity {SubscriptionClient.DefaultRule} Could not be found.");
191+
_logger.LogInformation($"The messaging entity { RuleDescription.DefaultRuleName } Could not be found.");
179192
}
180193
}
181194
}

src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.5-preview" />
9+
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="1.0.0" />
1010
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
1111
</ItemGroup>
1212

0 commit comments

Comments
 (0)