Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old stuff. Anyone maintaining this or new approach? #244

Open
belchski opened this issue Oct 15, 2022 · 7 comments
Open

Old stuff. Anyone maintaining this or new approach? #244

belchski opened this issue Oct 15, 2022 · 7 comments

Comments

@belchski
Copy link

No description provided.

@nikriaz
Copy link

nikriaz commented Apr 22, 2023

What is new approach?

@bugproof
Copy link

bugproof commented Aug 24, 2023

I think this approach is a bit too complicated imo. I would just solve it with triggers alone, insert record to some table like "change_notifications" and have a background service that checks this table for new records and sends out notifications/ using a queue and ordering items in a queue by "notification_time". At least for my use case that would work. I guess the approach in this repo is mostly based on something like https://stackoverflow.com/questions/305637/send-message-from-sql-server-trigger (didn't look deep into the code)

@nikriaz I think he meant this repo still uses System.Data.SqlClient instead of recommended Microsoft.Data.SqlClient for example.

@nikriaz
Copy link

nikriaz commented Aug 24, 2023

I looked closer to this problem and realized that it seems there is no reason to use any external libraries like this for this purpose. The only reason why people come here is multiple copy-pasted blog articles that referenced it.

I did my code based on the Microsoft.Data.SqlClient and specifically on SqlDataReader. The code is fairly simple, it's just a couple of dozens lines of code. Few months in production, works well. No triggers required. Not sure if I understand what is "a queue by "notification_time". None of them required. The basic idea how it works is registering a "snapshot" of some SELECT which is stored as notification stored procedure on the SQL server. As soon as content of the same SELECT changes, SQL emits notification that fires up the regular C# event.

I don't remember how I came up to the solution. ChatGPT, I think.

@bugproof
Copy link

bugproof commented Aug 24, 2023

I looked closer to this problem and realized that it seems there is no reason to use any external libraries like this for this purpose. The only reason why people come here is multiple copy-pasted blog articles that referenced it.

I did my code based on the Microsoft.Data.SqlClient and specifically on SqlDataReader. The code is fairly simple, it's just a couple of dozens lines of code. Few months in production, works well. No triggers required. Not sure if I understand what is "a queue by "notification_time". None of them required. The basic idea how it works is registering a "snapshot" of some SELECT which is stored as notification stored procedure on the SQL server. As soon as content of the same SELECT changes, SQL emits notification that fires up the regular C# event.

I don't remember how I came up to the solution. ChatGPT, I think.

So you're basically just comparing two SELECT results periodically(polling) and detecting what got deleted, added or changed. I would still choose the triggers over this or SQL server CDC (change data capture) feature. You already have service that pushes changes to kafka and uses CDC
https://debezium.io/
https://debezium.io/documentation/reference/stable/connectors/sqlserver.html

@nikriaz
Copy link

nikriaz commented Aug 25, 2023

No, of course no, No polling. I don't do it manually, server does it. Internal SQL mechanism seems to be the same to triggers but triggers have no built-in notification mechanism, they are supposed to be for data manipulation while you need notifications. So, it's like conditional triggers that emit notifications through service broker. Try to re-read the text for this library. It's not as complex as it looks like. General principles are explained correctly but you don't need this library itself: it's already built-in.

@bugproof
Copy link

@nikriaz Are you saying about change data capture feature?

@nikriaz
Copy link

nikriaz commented Aug 28, 2023

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants