TimeToFish 1.1.2
dotnet add package TimeToFish --version 1.1.2
NuGet\Install-Package TimeToFish -Version 1.1.2
<PackageReference Include="TimeToFish" Version="1.1.2" />
paket add TimeToFish --version 1.1.2
#r "nuget: TimeToFish, 1.1.2"
// Install TimeToFish as a Cake Addin
#addin nuget:?package=TimeToFish&version=1.1.2
// Install TimeToFish as a Cake Tool
#tool nuget:?package=TimeToFish&version=1.1.2
TimeToFish
Library for simple handling of time events to implement crontab like functionality using azure service bus events. Inspired by Passage of time event pattern
The library consist of two extension methods on the IServiceCollection interface. </br>
IServiceCollection ConfigureTimerJobs(this IServiceCollection services, string connectionString, string serviceName, params (Type jobType, string subscriptionName)[] jobs)
IServiceCollection ConfigureTimerJobs(this IServiceCollection services, TokenCredential tokenCredential, string fullyQualifiedNamespace, string entityName, string serviceName, params (Type jobType, string subscriptionName)[] jobs)
connectionString
: The connection string to the Azure Service Bus topic where the TimeHasPassed events are publishedserviceName
: Unique name of the servicejobs
: Array of tuples containingjobType
andsubscriptionName
.jobType
is the type of the class implementing the event handler/the job.subscriptionName
is the name of a subscription on the Topic. The topic should be configured to filter on the right Time events. Bluefin has a functionJobs.createJobSubscriptions
which can be used to create subscriptions.tokenCredential
: Azure Active Directory token authentication support.fullyQualifiedNamespace
: The fully qualified Service Bus namespace that the connection is associated with. This is likely to be similar to{yournamespace}.servicebus.windows.net
.entityName
: The name of the specific Service Bus entity instance under the associated Service Bus namespace.
Source code for Bluefin Jobs.createJobSubscriptions
can be found here
A JobHandler must implement the interface TimeToFish.ITimerJob
</br>
This interface has a single method: Task<HandlerResult> Handler(TimeEvent message)
The handler will be called when there is a message on the subscription and should return one of
HandlerResult.Success
HandlerResult.Failed
HandlerResult.Abort
// used when you don´t want any retries
Example:</br> Handlers:</br> <pre><code> public class MyFirstJob : ITimerJob { public Task<HandlerResult> Handler(TimeEvent message) { Console.WriteLine($"My first job was started. {DateTime.Now}"); return Task.FromResult(HandlerResult.Success()); }
public static (Type, string) JobDefinition { get => (typeof(MyFirstJob), "my-first-job"); }
}
public class MySecondJob : ITimerJob
{
public Task<HandlerResult> Handler(TimeEvent message)
{
Console.WriteLine($"My second job was started. {DateTime.Now}");
return Task.FromResult(HandlerResult.Success());
}
public static (Type, string) JobDefinition { get => (typeof(MySecondJob), "my-second-job"); }
}
</code></pre>
Initialization, typically in Program.cs
<pre><code>
await new HostBuilder()
.ConfigureServices((hostContext, services) ⇒
{
services.ConfigureTimerJobs(Configuration.GetConnectionString("timeTopic"),
"myservice",
MyFirstJob.JobDefinition,
MySecondJob.JobDefinition);
})
.RunConsoleAsync();
</code></pre>
or
<pre><code>
await new HostBuilder()
.ConfigureServices((hostContext, services) ⇒
{
services.ConfigureTimerJobs(new DefaultAzureCredential(),
"{yournamespace}.servicebus.windows.net",
"time.events",
"myservice",
MyFirstJob.JobDefinition,
MySecondJob.JobDefinition);
})
.RunConsoleAsync();
</code></pre>
This will register the two types MyFirstJob and MySecondJob in the IoC container, wire up the two jobs with the azure servicebus and register a HostedService that will contain the messaghandlers. The code will assume that there are two subscriptions named "myservice.my-first-job" and "myservice.my-second-job" registered on the topic.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Azure.Identity (>= 1.10.4)
- Azure.Messaging.ServiceBus (>= 7.17.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 3.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.