-
Notifications
You must be signed in to change notification settings - Fork 2
Muhannad/xchange created on multi queue #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee2d4ba
74a24bf
57c7bd8
52a333e
4a32829
4ce61cf
cd0f6b7
0205a5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using SW.Bitween.Domain; | ||
| using SW.Bitween.Model; | ||
| using SW.Bus.RabbitMqExtensions; | ||
| using SW.PrimitiveTypes; | ||
|
|
||
| namespace SW.Bitween.Domain; | ||
|
|
||
| public interface IWorkGroup | ||
| { | ||
| string BusMessageName { get; } | ||
| string GetBusMessageName(); | ||
| WorkGroupOptions Options { get; } | ||
| } | ||
|
|
||
| public class WorkGroup : BaseEntity,IWorkGroup | ||
| { | ||
| public string Name { get; set; } | ||
| public string BusMessageName { get; set; } | ||
|
|
||
| public string GetBusMessageName() => $"{Id}{BusMessageName}"; | ||
| //public string | ||
| public static WorkGroup None => new() { BusMessageName = "Ungrouped"}; | ||
| public WorkGroupOptions Options { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,18 @@ | |
|
|
||
| namespace SW.Bitween.Domain | ||
| { | ||
| internal abstract class XchangeCreatedEvent : BaseDomainEvent | ||
| internal class XchangeMessage | ||
| { | ||
| public string Id { get; set; } | ||
|
|
||
| } | ||
| internal abstract class XchangeCreatedEvent : BaseDomainEvent,IHasWorkGroup | ||
| { | ||
| public string Id { get; set; } | ||
| public string GetBusMessageName()=> WorkGroup.GetBusMessageName(); | ||
|
|
||
| public IWorkGroup WorkGroup { get; set; } | ||
|
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent null WorkGroup from breaking message routing.
🐛 Proposed fix- public string GetBusMessageName()=> WorkGroup.GetBusMessageName();
+ public string GetBusMessageName() =>
+ (WorkGroup ?? global::SW.Bitween.Domain.WorkGroup.None).GetBusMessageName();🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
| internal class ApiXchangeCreatedEvent : XchangeCreatedEvent | ||
| { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace SW.Bitween; | ||
|
|
||
| public interface IHasWorkGroup | ||
| { | ||
| public string Id { get; } | ||
| string GetBusMessageName(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ public interface IInfolinkCache | |
|
|
||
|
|
||
| void Revoke(); | ||
| void BroadcastRevoke(); | ||
| Task BroadcastRevoke(); | ||
|
|
||
| Task<WorkGroup[]> ListWorkGroupsAsync(); | ||
| Task<WorkGroup> WorkGroupByIdAsync(int workGroupId); | ||
| Task<WorkGroup> WorkGroupBySubscriptionIdAsync(int subscriptionId); | ||
|
Comment on lines
16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find implementations and call sites for BroadcastRevoke / IInfolinkCache
echo "=== BroadcastRevoke call sites ==="
rg -n --glob '!**/bin/**' --glob '!**/obj/**' 'BroadcastRevoke\s*\('
echo ""
echo "=== IInfolinkCache implementations ==="
rg -n --glob '!**/bin/**' --glob '!**/obj/**' ':\s*IInfolinkCache\b'Repository: simplify9/Bitween-api Length of output: 887 Fix unawaited The signature change to async (Task return) is correctly implemented in InMemoryBitweenCache, but four call sites fail to await:
These fire-and-forget calls risk dropping exceptions and race conditions in cache invalidation. Add 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System.Threading.Tasks; | ||
| using SW.Bitween.Domain; | ||
| using SW.Bitween.Model; | ||
| using SW.PrimitiveTypes; | ||
|
|
||
| namespace SW.Bitween.Resources.WorkGroups; | ||
|
|
||
| public class Create(BitweenDbContext dbContext, RequestContext requestContext,IInfolinkCache _BitweenCache, IBroadcast _broadcast) | ||
| : ICommandHandler<CreateWorkGroupModel, object> | ||
| { | ||
| private readonly RequestContext _requestContext = requestContext; | ||
|
|
||
| public async Task<object> Handle(CreateWorkGroupModel request) | ||
| { | ||
| var workgroup = new WorkGroup() | ||
| { | ||
| Name = request.Name, | ||
| BusMessageName = request.BusMessageName, | ||
| Options = new WorkGroupOptions() | ||
| { | ||
| RabbitMqOptions = new ConsumerSettings | ||
| { | ||
| Prefetch = request.Options?.RabbitMqOptions?.Prefetch, | ||
| Priority = request.Options?.RabbitMqOptions?.Priority | ||
| } | ||
| } | ||
| }; | ||
| dbContext.Add(workgroup); | ||
| await dbContext.SaveChangesAsync(); | ||
| _BitweenCache.BroadcastRevoke(); | ||
| await _broadcast.RefreshConsumers(); | ||
| return new | ||
| { | ||
| workgroup.Id | ||
| }; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.Threading.Tasks; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using SW.Bitween.Domain; | ||
| using SW.Bitween.Model; | ||
| using SW.PrimitiveTypes; | ||
|
|
||
| namespace SW.Bitween.Resources.WorkGroups; | ||
|
|
||
| [HandlerName(nameof(Delete))] | ||
| public class Delete(BitweenDbContext dbContext, RequestContext requestContext, IBroadcast _broadcast, IInfolinkCache _infolinkCache) | ||
| : ICommandHandler<int, DeleteWorkGroupModel, object> | ||
| { | ||
| private readonly RequestContext _requestContext = requestContext; | ||
|
|
||
| public async Task<object> Handle(int key, DeleteWorkGroupModel _) | ||
| { | ||
| var category = await dbContext.Set<WorkGroup>().FindAsync(key); | ||
| if (category is null) | ||
| throw new SWValidationException("CATEGORY_NOT_FOUND", $"Workgroup with id {key} was not found"); | ||
|
|
||
| if (await dbContext.Set<Subscription>().AnyAsync(i => i.WorkGroupId.Value == category.Id)) | ||
| throw new SWValidationException("CANT_BE_DELETED", "Workgroup with Subscriptions cant be deleted"); | ||
|
|
||
| //Todo chek rabbitMq | ||
| dbContext.Remove(category); | ||
| await dbContext.SaveChangesAsync(); | ||
| _infolinkCache.BroadcastRevoke(); | ||
| await _broadcast.RefreshConsumers(); | ||
|
Comment on lines
+24
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Await cache revocation to avoid fire‑and‑forget failures.
🐛 Proposed fix- _infolinkCache.BroadcastRevoke();
+ await _infolinkCache.BroadcastRevoke();🤖 Prompt for AI Agents |
||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Domain event publishing after
SaveChangesAsyncmay lose events on failure.The current flow commits database changes first (line 314), then publishes domain events (lines 321-331). If publishing fails (e.g., message broker unavailable), the database transaction has already committed but the events are lost. This can lead to data/event inconsistency.
Consider:
Also, line 315 contains commented-out code that should be removed.
🔒 Minimal improvement: add try-catch with logging
📝 Committable suggestion
🤖 Prompt for AI Agents