Sign inSign up

dkeshri/data-sync-emitter

By dkeshri

•Updated over 1 year ago

This image integrate with MsSql Database and RabitMq Message broker Send Changes to RabbitMq

Image
Databases & storage
0

1.3K

dkeshri/data-sync-emitter repository overview

⁠Data-Sync-Emmiter

This application help to track the change in MsSql Database changes and send that changes to RabbitMq Message broker. On Start of this application it create a Table called ChangeTrackers, Which contain list of tables that will be tracked. There is hosted service which check the Database change in every 10 secs and Send that changes to RabbiMq queue (default_queue: DataSyncQueue).

⁠Installation Steps

⁠Pre-requisite

Note: Before running image need some steps to perform

⁠Step 1: Enable Change tracking on Database

If not enabled please run below command.

ALTER DATABASE YourDatabaseName
SET CHANGE_TRACKING = ON 
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON);
⁠Step 2: Install RabbitMq. Skip this step if already installed.
docker run -d -v rabbitmqv:/var/log/rabbitmq --hostname rmq --name RabbitMqServer \
-p 5672:5672 -p 8080:15672 rabbitmq:3.13-management

⁠How to use this Image

⁠Method 1

⁠Step 1

Create docker-compose.yml file on your system and put below code in that file.

services:
  data-sync-emitter:
    container_name: data-sync-emitter
    image: dkeshri/data-sync-emitter:latest
    environment:
    - ConnectionStrings__DefaultConnection=Server=host.docker.internal,1433;Database=DatabaseName;User Id=userid;Password=Password;Encrypt=False
    - RabbitMq__HostName=host.docker.internal
    - RabbitMq__Port=5672
    - RabbitMq__UserName=guest
    - RabbitMq__Password=guest
    - RabbitMq__ClientProvidedName=Sender
    - RabbitMq__MessageRoutingKey=EmitterToReceiver
    - RabbitMq__Exchange__Name=DataSyncExchange
⁠Step 2

Run below command

docker-compose -f .\docker-compose.yml up -d

⁠Method 2

PowerShell

docker run -d `
  -e RabbitMq__HostName=host.docker.internal `
  -e RabbitMq__Port=5672 `
  -e RabbitMq__UserName=guest `
  -e RabbitMq__Password=guest `
  -e RabbitMq__ClientProvidedName=Sender `
  -e RabbitMq__Exchange__Name=DataSyncExchange `
  -e RabbitMq__MessageRoutingKey=EmitterToReceiver `
  -e ConnectionStrings__DefaultConnection="Server=host.docker.internal,1433;Database=YourDataBaseName;User Id=sa;Password=YourSqlPassword;Encrypt=False" `
  --name data-sync-emitter `
  dkeshri/data-sync-emitter:latest

⁠Configurations

You need to insert your table in ChangeTrackers Table. This table contains two column TableName and ChangeVersion. For ChangeVersion you need to set 0 as initial version

INSERT Into ChangeTrackers (TableName,ChangeVersion)
VALUES('YourTableName',0);

Note: Make sure dependent tableName should also be there in ChangeTrackers.

⁠Example

let say you have two tables orders and ordersSummary table and orders table has foreign refrance of ordersSummary table then you have to insert both tableName (orders and OrdersSummary) in ChangeTrackers Table.

After adding tables to the ChangeTrackers table, you need to restart the Emitter application to enable change tracking for the newly added tables.

If you don't want to restart the Emitter application, run the following query to manually enable change tracking

ALTER TABLE TableName
ENABLE CHANGE_TRACKING;

Tag summary

Content type

Image

Digest

sha256:bd3875462…

Size

83.2 MB

Last updated

over 1 year ago

docker pull dkeshri/data-sync-emitter