项目作者: WickedFlame

项目描述 :
Background task processing and message queue for .NET
高级语言: C#
项目地址: git://github.com/WickedFlame/Broadcast.git
创建时间: 2015-01-01T11:52:50Z
项目社区:https://github.com/WickedFlame/Broadcast

开源协议:Microsoft Public License

下载


WickedFlame Broadcast


Build Status
Build status
Build status
NuGet Version
NuGet Version

Quality Gate Status
Coverage
Lines of Code

Codacy Badge

Simple and easy to use background task processing and message queue for .NET

Broadcast is a simple implementation for processing and scheduling tasks in the background without blocking the main thread.
Broadcast helps implement the Mediator or CQRS (Command- and Queryhandling) patterns easily.

Visit https://wickedflame.github.io/Broadcast/ for the full documentation.

Installation

Broadcast is available as a NuGet package

  1. PM> Install-Package Broadcast

After installation setup the Processingserver in Startup.cs with a dashboard if desired

  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. ...
  4. services.AddBroadcast();
  5. }
  6. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  7. {
  8. ...
  9. app.UseBroadcastServer();
  10. app.UseBroadcastDashboard();
  11. }

Usage

Background Task processing

Processing a task in a async queue using the default Broadcaster

  1. BackgroundTaskClient.Send(() => Trace.WriteLine("This is a basic task"));

Processing a task with a custom Broadcaster instance

  1. var broadcaster = new Broadcaster();
  2. broadcaster.Send(() => Trace.WriteLine("This is a basic task"));

Scheduleed Tasks

Schedule a task in a async queue using the default Broadcaster

  1. BackgroundTaskClient.Schedule(() => Console.WriteLine("test"), TimeSpan.FromMinutes(1));

Schedule a task with a custom Broadcaster instance

  1. var broadcaster = new Broadcaster();
  2. broadcaster.Schedule(() => Console.WriteLine("test"), TimeSpan.FromMinutes(1));

Recurring Tasks

Add a recurring task to be processed in a async queue using the default Broadcaster

  1. BackgroundTaskClient.Recurring("recurring", () => service.Recurring(DateTime.Now.ToString("o")), TimeSpan.FromMinutes(15));

Add a recurring task to be processed with a custom Broadcaster instance

  1. var broadcaster = new Broadcaster();
  2. broadcaster.Recurring("recurring", () => service.Recurring(DateTime.Now.ToString("o")), TimeSpan.FromMinutes(15));