Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blendereru/jobconsumers
job consumers allow you to send messages of a large size.
https://github.com/blendereru/jobconsumers
masstransit saga-state-machine
Last synced: about 1 month ago
JSON representation
job consumers allow you to send messages of a large size.
- Host: GitHub
- URL: https://github.com/blendereru/jobconsumers
- Owner: blendereru
- License: apache-2.0
- Created: 2024-09-30T17:52:17.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-01T13:58:46.000Z (3 months ago)
- Last Synced: 2024-10-20T19:37:23.777Z (2 months ago)
- Topics: masstransit, saga-state-machine
- Language: C#
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JobConsumers
Conventional messages get immediately locked by brokers. Job consumers, on the other hand, allows you to decouple messages from the broker(that means all the report about the message state is internally handled by **sagas**).## How do they work ?
The job consumers are implemented through _IJobConsumer_ and contains one method that has to be overriden called Run(the same as Consume for consumers).
The specific configuration has to be applied in order to track the state of the messages.
```csharp
builder.Services.AddMassTransit(x =>
{
x.AddJobSagaStateMachines()
.EntityFrameworkRepository(e =>
{
e.ExistingDbContext();
});
}
```Internally, `AddJobSagaStateMachines()` method adds three saga state machines, each having their own purposes of tracking available job service instances.
```csharp
_jobTypeConfigurator = configurator.AddSagaStateMachine();
_jobConfigurator = configurator.AddSagaStateMachine();
_jobAttemptConfigurator = configurator.AddSagaStateMachine();
```* JobSaga: Orchestrates each job, including scheduling, retry, and failure handling
* JobAttemptSaga: Orchestrates each job attempt, communicating directly with a specific job service instance
* JobTypeSaga: Keep track of available job instances and allocates job slots to waiting jobs> Think of job slots as placeholders for active jobs. Once a job is being processed, a slot is "occupied," and it cannot be used for other jobs until the processing of that job is completed.
The DbContext should be configured in order to serve a storage for sagas, as by default, the `InMemoryRepository()` is used which is not durable.
```csharp
public class ImageStateDbContext : SagaDbContext
{
public ImageStateDbContext(DbContextOptions options) : base(options) {}
public DbSet Images { get; set; }protected override IEnumerable Configurations
{
get
{
yield return new JobTypeSagaMap(true);
yield return new JobSagaMap(true);
yield return new JobAttemptSagaMap(true);
}
}
}
```
And this is how each of the table might look like(1 - JobAttemptSaga, 2 - JobSaga, 3 - JobTypeSaga)
![img.png](img.png)