{"id":18866018,"url":"https://github.com/adia-dev/observer-pattern-dotnet","last_synced_at":"2026-02-12T15:30:19.274Z","repository":{"id":245187218,"uuid":"817499768","full_name":"adia-dev/observer-pattern-dotnet","owner":"adia-dev","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-19T21:11:06.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-18T06:47:08.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adia-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-19T21:10:08.000Z","updated_at":"2024-06-19T21:11:48.000Z","dependencies_parsed_at":"2024-06-20T11:24:00.019Z","dependency_job_id":"d37933b1-1abc-4925-8d27-9952fef87a8e","html_url":"https://github.com/adia-dev/observer-pattern-dotnet","commit_stats":null,"previous_names":["adia-dev/observer-pattern-dotnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fobserver-pattern-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fobserver-pattern-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fobserver-pattern-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fobserver-pattern-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adia-dev","download_url":"https://codeload.github.com/adia-dev/observer-pattern-dotnet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239810069,"owners_count":19700732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T05:05:19.591Z","updated_at":"2026-02-12T15:30:19.209Z","avatar_url":"https://github.com/adia-dev.png","language":"C#","readme":"# Mini Kafka - Observer Pattern Example\n\nThis project is a simple implementation of a mini Kafka system to learn about the Observer pattern in C#. It demonstrates how publishers (producers) and subscribers (consumers) can communicate using the observer pattern.\n\n## Project Structure\n\n- **AbstractNotifier.cs**: Defines an abstract class that manages topic-based subscriptions and notifications.\n- **KafkaProducer.cs**: Represents a producer that adds messages to topics in Kafka.\n- **Kafka.cs**: Manages the storage of messages and notifies subscribers when new messages are added.\n- **Program.cs**: The main entry point that sets up the Kafka system, creates consumers, and produces messages periodically.\n- **KafkaStream.cs**: Implements the notification mechanism for subscribers based on topics.\n- **KafkaConsumer.cs**: Represents a consumer that receives messages for a specific topic.\n- **ISubscriber.cs**: An interface that defines the update method for subscribers.\n\n## How It Works\n\n1. **Publisher/Subscriber Management**:\n   - `AbstractNotifier` manages subscribers based on topics. It provides methods to subscribe, unsubscribe, and notify subscribers.\n\n2. **Producing Messages**:\n   - `KafkaProducer` adds messages to topics in the `Kafka` class.\n   - `Kafka` stores messages and notifies the relevant subscribers when a new message is added to a topic.\n\n3. **Consuming Messages**:\n   - `KafkaConsumer` implements the `ISubscriber` interface and receives updates when new messages are available for its subscribed topic.\n\n4. **Periodic Message Production**:\n   - `Program.cs` simulates message production at random intervals. It sets up the Kafka system, subscribes consumers to topics, and produces messages periodically until a key is pressed to stop.\n\n## Running the Project\n\n1. Clone the repository.\n2. Open the project in your preferred IDE.\n3. Build and run the project.\n\n```bash\ndotnet run\n```\n\n4. The program will start producing messages at random intervals. Press any key to stop the production of messages.\n\n## Example Output\n\n```\nmini-kafka started.\nProduced message: Message at 6/19/2024 10:24:25 AM to topic: code.execution.request\nMessage received on consumer 123e4567-e89b-12d3-a456-426614174000 for topic code.execution.request\n...\nPress any key to stop producing messages...\nStopped producing messages.\n```\n\n## Learning Objectives\n\nThis project aims to help you understand the following concepts:\n\n- **Observer Pattern**: Learn how to implement the observer pattern to manage publishers and subscribers.\n- **Topic-Based Subscription**: Understand how to manage subscriptions based on topics.\n- **Asynchronous Programming**: Get hands-on experience with asynchronous programming using `Task` and `CancellationToken`.\n\n## Future Improvements (will probably never happen)\n\n- **Thread Safety**: Implement thread-safe collections or locking mechanisms to handle concurrent access.\n- **Error Handling**: Add proper error handling throughout the code.\n- **Logging**: Integrate a logging framework to provide more detailed logs.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadia-dev%2Fobserver-pattern-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadia-dev%2Fobserver-pattern-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadia-dev%2Fobserver-pattern-dotnet/lists"}