Dkeshri.DataSync.DbChangeReceiver 1.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Dkeshri.DataSync.DbChangeReceiver --version 1.1.3                
NuGet\Install-Package Dkeshri.DataSync.DbChangeReceiver -Version 1.1.3                
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="Dkeshri.DataSync.DbChangeReceiver" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dkeshri.DataSync.DbChangeReceiver --version 1.1.3                
#r "nuget: Dkeshri.DataSync.DbChangeReceiver, 1.1.3"                
#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.
// Install Dkeshri.DataSync.DbChangeReceiver as a Cake Addin
#addin nuget:?package=Dkeshri.DataSync.DbChangeReceiver&version=1.1.3

// Install Dkeshri.DataSync.DbChangeReceiver as a Cake Tool
#tool nuget:?package=Dkeshri.DataSync.DbChangeReceiver&version=1.1.3                

Data-Sync-Receiver

This will subscribe to Message Broker like RabbitMq Queue. On Message received, Apply changes to MSSQL Database. This package only support RabbitMQ.

Installation Steps

Pre-requisite

Message Broker need to be running. (RabbitMq)

How to Use

This package is using the IServiceCollection to setup. There is an Extension AddDbChangeReceiver Method is use to setup.

you need to provide Message Broker Details (like rabbitMq) and MsSql Connection details to work this package.

Receive Message from Queue

If you want to receive message that are send directly to queue then you need to set only Queue Propperties of RabbitMq Config.

Step 1

For Queue

services.AddDbChangeReceiver((config) =>
{
    config.MessageBroker.AddRabbitMqServices((rabbitMqConfig) =>
    {
        rabbitMqConfig.HostName = "rabbitMqHostIp";
        rabbitMqConfig.Port = 5672; 
        rabbitMqConfig.UserName = "userName";
        rabbitMqConfig.Password = "password";
        rabbitMqConfig.Queue.QueueName = "QueueName";
    });

    config.AddDataLayer((dbType, config) =>
    {
        dbType = DatabaseType.MSSQL;
        config.ConnectionString = "Server=hostIp;Database=DatabaseName;User Id=userid;Password=YourDbPassword;Encrypt=False";
        config.TransactionTimeOutInSec = 30;
    });
});

For Exchange

services.AddDbChangeReceiver((config) =>
{
    config.MessageBroker.AddRabbitMqServices((rabbitMqConfig) =>
    {
        rabbitMqConfig.HostName = "rabbitMqHostIp";
        rabbitMqConfig.Port = 5672; 
        rabbitMqConfig.UserName = "userName";
        rabbitMqConfig.Password = "password";
        rabbitMqConfig.Queue.QueueName = "QueueName";
        rabbitMqConfig.Queue.ExchangeName = "ExchangeName";
        rabbitMqConfig.Queue.RoutingKeys = ["RoutingKey1"];
    });

    config.AddDataLayer((dbType, config) =>
    {
        dbType = DatabaseType.MSSQL;
        config.ConnectionString = "Server=hostIp;Database=DatabaseName;User Id=userid;Password=YourDbPassword;Encrypt=False";
        config.TransactionTimeOutInSec = 30;
    });
});

**Step 2 😗*After Service Configuration call UseDbChangeReceiver Extension Method of Ihost

var host = builder.UseConsoleLifetime().Build();
host.UseDbChangeReceiver();

Full Example for Queue

Lets say we have .Net Core Console Application, Use below code in Program.cs file and run the application.

using Dkeshri.DataSync.DbChangeReceiver.Extenstions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Dkeshri.MessageQueue.RabbitMq.Extensions;

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureServices((hostContext, services) =>
{
    services.AddDbChangeReceiver((config) =>
    {
        config.MessageBroker.AddRabbitMqServices((rabbitMqConfig) =>
        {
            rabbitMqConfig.HostName = "rabbitMqHostIp";
            rabbitMqConfig.Port = 5672; 
            rabbitMqConfig.UserName = "userName";
            rabbitMqConfig.Password = "password";
            rabbitMqConfig.Queue.QueueName = "QueueName";
        });

        config.AddDataLayer((dbType, config) =>
        {
            dbType = DatabaseType.MSSQL;
            config.ConnectionString = "Server=hostIp;Database=DatabaseName;User Id=userid;Password=YourDbPassword;Encrypt=False";
            config.TransactionTimeOutInSec = 30;
        });
    });
});

var host = builder.UseConsoleLifetime().Build();

host.UseDbChangeReceiver();

host.RunAsync().Wait();

Full Example for Exchange

using Dkeshri.DataSync.DbChangeReceiver.Extenstions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Dkeshri.MessageQueue.RabbitMq.Extensions;

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureServices((hostContext, services) =>
{
    services.AddDbChangeReceiver((config) =>
    {
        config.MessageBroker.AddRabbitMqServices((rabbitMqConfig) =>
        {
            rabbitMqConfig.HostName = "rabbitMqHostIp";
            rabbitMqConfig.Port = 5672; 
            rabbitMqConfig.UserName = "userName";
            rabbitMqConfig.Password = "password";
            rabbitMqConfig.Queue.QueueName = "QueueName";
            rabbitMqConfig.Queue.ExchangeName = "ExchangeName";
            rabbitMqConfig.Queue.RoutingKeys = ["RoutingKey1"];
        });

        config.AddDataLayer((dbType, config) =>
        {
            dbType = DatabaseType.MSSQL;
            config.ConnectionString = "Server=hostIp;Database=DatabaseName;User Id=userid;Password=YourDbPassword;Encrypt=False";
            config.TransactionTimeOutInSec = 30;
        });
    });
});

var host = builder.UseConsoleLifetime().Build();

host.UseDbChangeReceiver();

host.RunAsync().Wait();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.