FSharpWorks.Outbox.MSSQL 0.1.24

There is a newer version of this package available.
See the version list below for details.
dotnet add package FSharpWorks.Outbox.MSSQL --version 0.1.24
                    
NuGet\Install-Package FSharpWorks.Outbox.MSSQL -Version 0.1.24
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharpWorks.Outbox.MSSQL" Version="0.1.24" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSharpWorks.Outbox.MSSQL" Version="0.1.24" />
                    
Directory.Packages.props
<PackageReference Include="FSharpWorks.Outbox.MSSQL" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FSharpWorks.Outbox.MSSQL --version 0.1.24
                    
#r "nuget: FSharpWorks.Outbox.MSSQL, 0.1.24"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FSharpWorks.Outbox.MSSQL@0.1.24
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FSharpWorks.Outbox.MSSQL&version=0.1.24
                    
Install as a Cake Addin
#tool nuget:?package=FSharpWorks.Outbox.MSSQL&version=0.1.24
                    
Install as a Cake Tool

FSharpWorks.Outbox.MSSQL

An MSSQL backend for FSharpWorks.Outbox: transactional outbox pattern implementation.

Using the MSSQL backend

Please refer to Readme in FSharpWorks.Outbox project for a complete example.

In order to create a backend, MSSQL.createBackend function is used:

Example (F#)

open FSharpWorks.Outbox

let dbOptions =
    { connectionString = ConnectionString "Server=127.0.0.1;Database=service;User Id=sa;Password=Password1"
      schema = SchemaName "dbo"
      name = OutboxName "my-outbox" }


// Use Postgres backend in this example
let mssqlBackend = MSSQL.createBackend dbOptions

Example (C#)

using FSharpWorks.Outbox
using FSharpWorks.Outbox.CSharp

var dbOptions = OutboxFactory.CreateOutboxParams(
    ConnectionString.NewConnectionString("Server=127.0.0.1;Database=service;User Id=sa;Password=Password1"),
    SchemaName.NewSchemaName("dbo"),
    OutboxName.NewOutboxName("my-outbox"));

// Use MSSQL backend in this example
var mssqlBackend = MSSQL.CreateBackend(dbOptions);

The backend then can be used for creating FSharpWorks.Outbox.

Schema

DB Schema can be automatically set up by the backend or it can be set up externally (for example, using DB deployment/provisioning tools).

When an auto-initialisation is called for an outbox named MyOutbox, the following schema will be generated in the DB:

CREATE SEQUENCE MyOutboxSequence
    AS [bigint]
    START WITH 1
    INCREMENT BY 1
    NO CYCLE
    NO CACHE

GO

CREATE TABLE [MyOutbox] (
    [SequenceId] BIGINT NOT NULL DEFAULT NEXT VALUE FOR MyOutboxSequence,
    [RowVersion] ROWVERSION NOT NULL,
    [MessageType] VARCHAR(255) NOT NULL,
    [Payload] VARBINARY(MAX) NOT NULL,
    [DateAddedUtc] DATETIME2(3) NOT NULL DEFAULT SYSUTCDATETIME(),
    CONSTRAINT [PK_MyOutbox] PRIMARY KEY NONCLUSTERED([SequenceId])
        WITH (FILLFACTOR = 100, DATA_COMPRESSION = PAGE)
)

GO

CREATE CLUSTERED INDEX [IX_MyOutbox]
    ON [MyOutbox]([RowVersion])
    WITH (FILLFACTOR = 100, DATA_COMPRESSION = PAGE)

GO

CREATE PROCEDURE MyOutbox_Enqueue (
    @MessageType AS VARCHAR(255),
    @Payload AS VARBINARY(MAX)
) AS
    INSERT INTO [MyOutbox] ([MessageType], [Payload])
    VALUES (@MessageType, @Payload)

GO

CREATE PROCEDURE MyOutbox_Dequeue (
    @MAX_MESSAGES_NUM AS INT = 5
) AS
    WITH OrderedOutboxMessages AS (
        SELECT TOP (@MAX_MESSAGES_NUM) *
        FROM
            [MyOutbox] WITH(UPDLOCK, READPAST)
        WHERE
            [RowVersion] <= MIN_ACTIVE_ROWVERSION()
        ORDER BY
            [RowVersion]
    )
    DELETE
    FROM OrderedOutboxMessages
    OUTPUT DELETED.*

Tuning the schema

The backend only relies on two stored procedures:

  • <outbox-name>_Enqueue for enqueuing messages into the outbox
  • <outbox-name>_Dequeue for dequeuing messages and dispatching them externally.

As long as they exist (and comply with their expected signatures, see the schema above), the rest of the schema (tables, indices, procedures' implementations) can be changed freely as it is never used by the backend directly.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.35 4,218 7/22/2021
0.1.34 423 7/22/2021
0.1.33 405 7/21/2021
0.1.32 427 7/19/2021
0.1.31 434 7/19/2021
0.1.28 484 7/15/2021
0.1.27 466 7/14/2021
0.1.25 433 7/14/2021
0.1.24 453 7/14/2021
0.1.23 479 7/13/2021
0.1.22 483 7/9/2021
0.1.21 472 7/8/2021
0.1.17 443 7/6/2021
0.1.14 455 7/2/2021
0.1.13 475 7/1/2021