### Install Sstv.Outbox NuGet Packages Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Install the necessary Sstv.Outbox NuGet packages using the .NET CLI or PackageReference in your project file. ```powershell dotnet add Sstv.Outbox.EntityFrameworkCore.Npgsql or Sstv.Outbox.Npgsql -- if need kafka: dotnet add Sstv.Outbox.Kafka ``` -------------------------------- ### Outbox Configuration via appsettings.json Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Illustrates how to configure outbox behavior, such as worker enablement, item limits, worker type, and delay, using the `appsettings.json` file. ```json { "Outbox": { "NotificationMessageOutboxItem": { "IsWorkerEnabled": true, "OutboxItemsLimit": 10, "WorkerType": "ef_competing", "WorkerDelay": "00:00:05" }, "other": { } } } ``` -------------------------------- ### Publishing Notification Messages via Outbox Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Demonstrates how to publish `NotificationMessage` by creating an `OutboxItem` using `IKafkaOutboxItemFactory` and adding it to the `DbContext`. ```csharp public class NotificationPublisher { private readonly IKafkaOutboxItemFactory _factory; private readonly ApplicationDbContext _ctx; public NotificationPublisher(IKafkaOutboxItemFactory factory, ApplicationDbContext ctx) { _factory = factory; _ctx = ctx; } public void Notify(NotificationMessage message) { ArgumentNullException.ThrowIfNull(message); var item = _factory.Create( key: message.Id, value: message ); _ctx.NotificationMessageOutboxItems.Add(item); } } ``` -------------------------------- ### Add Sstv.Outbox NuGet Packages via PackageReference Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Alternatively, add the Sstv.Outbox NuGet packages to your project by including them in the PackageReference section of your .csproj file. ```xml ``` -------------------------------- ### OutboxItem Behavior Configuration via Lambda Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Shows how to configure outbox item behavior, including worker type, enablement, item limits, delay, retry settings, and custom UUID generation, using a lambda expression in `AddOutboxItem`. ```csharp services .AddOutboxItem(options => { options.WorkerType = WorkerType.ef_strict_ordering; options.IsWorkerEnabled = true; options.OutboxItemsLimit = 50; options.OutboxDelay = TimeSpan.FromSeconds(5); options.RetrySettings = new RetrySettings { ... }; options.NextGuid = () => Guid.NewGuid(); // Example for custom UUID generation }); ``` -------------------------------- ### Kafka Outbox Item Entity and Configuration Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Defines the `NotificationMessageOutboxItem` entity, its `DbContext` DbSet, and its Entity Framework Core configuration, including primary key and JSON column type for headers. ```csharp public class NotificationMessageOutboxItem : IKafkaOutboxItem { public Guid Id { get; init; } // other fields omited for brevity } // Add DbSet to DbContext: internal sealed class ApplicationContext : DbContext { public DbSet NotificationMessageOutboxItems { get; set; } = null!; } // Configure table internal sealed class NotificationMessageOutboxItemConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { ArgumentNullException.ThrowIfNull(builder); builder.HasKey(x => x.Id); builder .Property(x => x.Id) .ValueGeneratedNever(); builder .Property(x => x.Headers) .HasColumnType("json"); } } ``` -------------------------------- ### Kafka Producer Configuration and DI Registration Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Registers the outbox item with Kafka producer configuration, including topic name, serializers, and a custom `ProducerBuilder` with `ProducerConfig`. ```csharp // Register to DI: services .AddOutboxItem() .WithKafkaProducer, TOutboxItem, Guid, NotificationMessage>( new KafkaTopicConfig { DefaultTopicName = "notification-messages", KeyDeserializer = new UuidBinarySerializer(), KeySerializer = new UuidBinarySerializer(), ValueDeserializer = new SystemTextJsonSerializer(), ValueSerializer = new SystemTextJsonSerializer(), // provide here IProducer with your configuration. Producer = new ProducerBuilder(new ProducerConfig { SecurityProtocol = SecurityProtocol.Plaintext, BootstrapServers = "localhost:9092" }).Build() }); ``` -------------------------------- ### one_more_outbox_items Table Schema Source: https://github.com/mt89vein/sstv.outbox/blob/master/tests/Sstv.Outbox.Sample/readme.md Defines the schema for the `one_more_outbox_items` table, an alternative outbox table structure. ```sql CREATE TABLE one_more_outbox_items ( id uuid NOT NULL, created_at timestamptz DEFAULT (now() at time zone 'utc') NOT NULL, status int4 default 0 NOT NULL, retry_count int4 NULL, retry_after timestamptz NULL, headers bytea NULL, data bytea NULL, CONSTRAINT pk_one_more_outbox_items PRIMARY KEY (id) ); ``` -------------------------------- ### Outbox Full Batches Counter Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Counts how many times full batches have been fetched. If OutboxItemsLimit is set to 100, this metric indicates how many times 100 items were fetched. It may suggest high worker utilization, potentially requiring more worker instances. ```text # TYPE outbox_items_full_batches counter # HELP outbox_items_full_batches_total Counts how many times fetched full batches. outbox_items_full_batches_total{outbox_name="KafkaEfOutboxItem"} ``` -------------------------------- ### Outbox Items Fetched Counter Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Counts how many outbox items have been fetched from the database. ```text # TYPE outbox_items_fetched_total counter # HELP outbox_items_fetched_total Counts how many outbox items fetched. outbox_items_fetched_total{outbox_name="KafkaEfOutboxItem"} ``` -------------------------------- ### my_outbox_items Table Schema Source: https://github.com/mt89vein/sstv.outbox/blob/master/tests/Sstv.Outbox.Sample/readme.md Defines the schema for the `my_outbox_items` table, used for storing outbox messages. ```sql CREATE TABLE my_outbox_items ( id uuid NOT NULL, created_at timestamptz DEFAULT (now() at time zone 'utc') NOT NULL, status int4 default 0 NOT NULL, retry_count int4 NULL, retry_after timestamptz NULL, headers bytea NULL, data bytea NULL, CONSTRAINT pk_my_outbox_items PRIMARY KEY (id) ); ``` -------------------------------- ### Handler Duration Metrics Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Measures the duration of processing by the outbox item handler. ```text # TYPE outbox_worker_handler_duration histogram # HELP outbox_worker_handler_duration Measures duration of processing by outbox item handler. outbox_worker_handler_duration_bucket{batched="False",outbox_name="KafkaEfOutboxItem",le="0"} outbox_worker_handler_duration_sum{batched="False",outbox_name="KafkaEfOutboxItem"} outbox_worker_handler_duration_count{batched="False",outbox_name="KafkaEfOutboxItem"} ``` -------------------------------- ### Worker Process Duration Metrics Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Measures the duration of the worker process for one batch, from fetching data to full processing and saving. Useful for detecting performance problems. ```text # TYPE outbox_worker_process_duration histogram # HELP outbox_worker_process_duration Measures duration of worker process one batch. outbox_worker_process_duration_bucket{outbox_name="KafkaEfOutboxItem",le="0"} 0 outbox_worker_process_duration_sum{outbox_name="KafkaEfOutboxItem"} 0 outbox_worker_process_duration_count{outbox_name="KafkaEfOutboxItem"} 0 ``` -------------------------------- ### strict_outbox_items Table Schema Source: https://github.com/mt89vein/sstv.outbox/blob/master/tests/Sstv.Outbox.Sample/readme.md Defines the schema for the `strict_outbox_items` table, designed for strict outbox message handling. ```sql CREATE TABLE strict_outbox_items ( id uuid NOT NULL, created_at timestamptz DEFAULT (now() at time zone 'utc') NOT NULL, status int4 default 0 NOT NULL, retry_count int4 NULL, retry_after timestamptz NULL, headers bytea NULL, data bytea NULL, CONSTRAINT pk_strict_outbox_items PRIMARY KEY (id) ); ``` -------------------------------- ### Outbox Items Processed Counter Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Counts how many outbox items have been processed. ```text # TYPE outbox_items_processed_total counter # HELP outbox_items_processed_total Counts how many outbox items processed. outbox_items_processed_total{outbox_name="KafkaEfOutboxItem"} ``` -------------------------------- ### Outbox Items Retried Counter Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Counts how many outbox items have been retried. ```text # TYPE outbox_items_retried counter # HELP outbox_items_retried_total Counts how many outbox items retried. outbox_items_retried_total{outbox_name="KafkaEfOutboxItem"} ``` -------------------------------- ### Worker Sleep Duration Metrics Source: https://github.com/mt89vein/sstv.outbox/blob/master/readme.md Measures the duration of worker sleep between batches. This can be less than the OutboxDelay setting due to the use of PeriodicTimer. ```text # TYPE outbox_worker_sleep_duration histogram # HELP outbox_worker_sleep_duration Measures duration of worker sleep between batches. outbox_worker_sleep_duration_bucket{outbox_name="KafkaEfOutboxItem",le="0"} outbox_worker_sleep_duration_sum{outbox_name="KafkaEfOutboxItem"} outbox_worker_sleep_duration_count{outbox_name="KafkaEfOutboxItem"} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.