https://github.com/mizrael/webapiwithbackgroundworker
Small demo showing how to implement Pub/Sub with a BackgroundWorker in .NET Core
https://github.com/mizrael/webapiwithbackgroundworker
dotnet dotnet-core pubsub rabbitmq webapi webapi-core
Last synced: 3 months ago
JSON representation
Small demo showing how to implement Pub/Sub with a BackgroundWorker in .NET Core
- Host: GitHub
- URL: https://github.com/mizrael/webapiwithbackgroundworker
- Owner: mizrael
- Created: 2019-11-05T12:40:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T14:44:51.000Z (over 2 years ago)
- Last Synced: 2025-02-27T21:50:02.968Z (4 months ago)
- Topics: dotnet, dotnet-core, pubsub, rabbitmq, webapi, webapi-core
- Language: C#
- Homepage: https://www.davidguida.net/consuming-message-queues-using-net-core-background-workers-part-1-message-queues/
- Size: 33.2 KB
- Stars: 78
- Watchers: 3
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Description
This repository contains a simple implementation of Pub/Sub in .NET Core. This code has been used as example accompaining a series of articles on my personal blog: https://www.davidguida.net/consuming-message-queues-using-net-core-background-workers-part-1-message-queues/## The Publisher
The Publisher is implemented a simple Console application. The user will be prompted to write a text message which will be sent to a RabbitMQ fanout exchange.## The Subscriber
The Subscriber is implemented as a .NET Core Background Worker hosted in a Web API. The Worker is starting the subscriber and listening for incoming messages.Messages are internally processed using a Producer/Consumer mechanism leveraging the System.Threading.Channels library.
Once a message is received, the worker will send it to a Producer which will then dispatch on a Channel. A certain number of Consumers has been registered at bootstrap. The first available Consumer will pick up the message and store it in a repository.
The Web API exposes a single GET endpoint /messages which will return the list of received messages.
For more details about Producer/Consumer, check this article: https://www.davidguida.net/how-to-implement-producer-consumer-with-system-threading-channels/