Skip to content

Commit 68b1b50

Browse files
MnatsakanMargaryanMnatsakanMargaryan
authored andcommitted
fix
1 parent a8d2be2 commit 68b1b50

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

MassTransit.PostgresOutbox.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ VisualStudioVersion = 17.9.34723.18
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransit.PostgresOutbox", "src\PandaNuGet\MassTransit.PostgresOutbox.csproj", "{25001943-A870-4E17-A9B9-0D190CEC819B}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PandaNuGet.Tests", "test\PandaNuGet.Tests\PandaNuGet.Tests.csproj", "{0305E58F-1C47-454C-B10B-A223F2561A85}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransit.PostgresOutbox.Tests", "test\PandaNuGet.Tests\MassTransit.PostgresOutbox.Tests.csproj", "{0305E58F-1C47-454C-B10B-A223F2561A85}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PandaNuGet.Demo", "test\PandaNuGet.Demo\PandaNuGet.Demo.csproj", "{8A6AA36D-1CEF-4018-9C9D-7D029F3EAECE}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransit.PostgresOutbox.Demo", "test\PandaNuGet.Demo\MassTransit.PostgresOutbox.Demo.csproj", "{8A6AA36D-1CEF-4018-9C9D-7D029F3EAECE}"
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F8A6DCFE-8924-49A4-B3E9-2034593F54E5}"
1313
EndProject

Readme.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,74 @@ Stay tuned for the next sections where we'll cover the usage details, showcasing
4343
extension to enhance your distributed systems.
4444

4545
## Usage
46+
Take into account that examples below are given for configuring both inbox and outbox patterns.
47+
If you need only one of those , consider using appropriate methods available(eg. instead of AddOutboxInboxServices use AddInboxServices and etc).
48+
49+
Configuration
50+
51+
Entity Configuration: Ensure your DbContext implements the IOutboxDbContext and IInboxDbContext interfaces.
52+
Configure your entities and generate migrations.
53+
Call ConfigureInboxOutboxEntities on your ModelBuilder to configure the necessary tables for inbox and outbox patterns.
54+
55+
```csharp
56+
57+
protected override void OnModelCreating(ModelBuilder modelBuilder)
58+
{
59+
modelBuilder.ConfigureInboxOutboxEntities();
60+
}
61+
```
62+
63+
Service Registration: Register essential services on startup, specifying the DbContext type.
64+
You can optionally override settings(its optional parameter).
65+
66+
```csharp
67+
68+
services.AddOutboxInboxServices<PostgresContext>();
69+
```
70+
71+
Publishing Messages (Outbox Pattern)
72+
73+
To publish a message using the outbox pattern, call the AddToOutbox method on your DbContext,
74+
specifying your message. Remember to call SaveChanges() to persist the message to the database.
75+
76+
```csharp
77+
78+
dbContext.Orders.Add(new Order
79+
{
80+
Amount = 555,
81+
CreatedAt = DateTime.UtcNow,
82+
});
83+
84+
// Add message to the outbox
85+
dbContext.AddToOutbox(new OrderCreatedEvent());
86+
87+
// Save changes to the database
88+
dbContext.SaveChanges();
89+
```
90+
91+
Consuming Messages (Inbox Pattern)
92+
93+
To consume messages using the inbox pattern, create a consumer that inherits from
94+
InboxConsumer<TMessage, TDbContext> class, specifying the message type and DbContext type as generic arguments.
95+
96+
```csharp
97+
98+
public class YourConsumer : InboxConsumer<YourMessage, PostgresContext>
99+
{
100+
private readonly PostgresContext _context;
101+
102+
public YourConsumer(PostgresContext dbContext, IServiceScopeFactory serviceScopeFactory)
103+
: base(serviceScopeFactory)
104+
{
105+
_context = dbContext;
106+
}
107+
108+
public override async Task Consume(YourMessage message)
109+
{
110+
// Implement your message processing logic here
111+
}
112+
}
113+
```
46114

47115
## License
48116

src/PandaNuGet/Class1.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
public class Class1
44
{
5-
//todo refactor lib and test names using PascalCase and not adding Pandatech. prefix
6-
//Refactor NuGet package .csproj file
75
//Refactor CI/CD pipeline
86
//UPDATE README both in the project and outside of project. Outside is for github, inside is for nuget.org
9-
//Make repository public in order to read nuget.org keys!
107
//Create main branch and merge in order CI to start its work
11-
//Always work on development and test yourself
128
}

test/PandaNuGet.Tests/PandaNuGet.Tests.csproj renamed to test/PandaNuGet.Tests/MassTransit.PostgresOutbox.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>

0 commit comments

Comments
 (0)