https://github.com/turgayozgur/tossit
Library for distributed job/worker logic.
https://github.com/turgayozgur/tossit
distributed dotnetcore job rabbitmq worker
Last synced: 3 months ago
JSON representation
Library for distributed job/worker logic.
- Host: GitHub
- URL: https://github.com/turgayozgur/tossit
- Owner: turgayozgur
- License: mit
- Created: 2017-01-24T21:38:42.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T03:42:46.000Z (almost 3 years ago)
- Last Synced: 2025-08-20T03:09:55.823Z (3 months ago)
- Topics: distributed, dotnetcore, job, rabbitmq, worker
- Language: C#
- Homepage:
- Size: 99.6 KB
- Stars: 61
- Watchers: 6
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- system-architecture-awesome - Tossit - Simple, easy to use library for distributed job/worker logic. Distributed messages handled by built in RabbitMQ implementation. (Queue and Messaging)
- awesome-dotnet-core - Tossit - 简单易用的库,用于分布式作业/工作人员逻辑。内置RabbitMQ实现处理的分布式消息。 (框架, 库和工具 / 消息队列)
- fucking-awesome-dotnet-core - Tossit - Simple, easy to use library for distributed job/worker logic. Distributed messages handled by built in RabbitMQ implementation. (Frameworks, Libraries and Tools / Queue and Messaging)
- awesome-dotnet-core - Tossit - Simple, easy to use library for distributed job/worker logic. Distributed messages handled by built in RabbitMQ implementation. (Frameworks, Libraries and Tools / Queue and Messaging)
- awesome-software-architecture - tossit
- awesome-dotnet-core - Tossit - Simple, easy to use library for distributed job/worker logic. Distributed messages handled by built in RabbitMQ implementation. (Frameworks, Libraries and Tools / Queue and Messaging)
README
# Tossit #
[](https://www.nuget.org/packages/Tossit.RabbitMQ)
[](https://travis-ci.org/turgayozgur/tossit)
[](https://ci.appveyor.com/project/turgayozgur/tossit/branch/master)

[](https://codecov.io/gh/turgayozgur/tossit)
[](https://gitter.im/tossitchat/Lobby)
Simple, easy to use library for distributed job/worker logic. Distributed messages handled by built in [RabbitMQ](https://github.com/rabbitmq/rabbitmq-dotnet-client) implementation.
## Highlights ##
* Super easy way to use RabbitMQ .net client for job/worker logic.
* Connection and channel management.
* Failure management.
* Send and receive data that auto converted to your object types.
* Recovery functionality. Do not worry about connection loses.
## Installation ##
You need to install [Tossit.RabbitMQ](https://www.nuget.org/packages/Tossit.RabbitMQ) nuget package.
```
PM> Install-Package Tossit.RabbitMQ
```
Use ConfigureServices method on startup to register services.
```csharp
public void ConfigureServices(IServiceCollection services)
{
// Add RabbitMQ implementation dependencies.
services.AddRabbitMQ();
// Warning!
// Call only AddTossitJob method or only AddTossitWorker method which one you need.
// Call both of them, if current application contains worker and job.
// Add Tossit Job dependencies.
services.AddTossitJob();
// Add Tossit Worker dependencies.
services.AddTossitWorker();
}
```
Then, use configure method to configuring RabbitMQ server and prepare workers.
```csharp
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Use RabbitMQ server.
app.UseRabbitMQServer("amqp://guest:guest@localhost");
// Warning!
// Call UseTossitWorker method, if current application contains worker.
// If this application has worker(s), register it.
app.UseTossitWorker();
}
```
## Job Usage ##
Create a new class to sending to worker(s).
```csharp
public class FooData
{
public int Id { get; set; }
}
```
Create a new job class to dispatch data to worker(s).
```csharp
public class FooJob : IJob
{
public FooData Data { get; set; }
public string Name => "foo.job.name"; // Job name should be unique for each job.
}
```
Dispatch job using IJobDispatcher.
```csharp
[Route("api/[controller]")]
public class AnyController : Controller
{
private readonly IJobDispatcher _jobDispatcher;
public AnyController(IJobDispatcher jobDispatcher)
{
_jobDispatcher = jobDispatcher;
}
[HttpGet]
public IActionResult Create()
{
// Dispatch job.
var isDispatched = _jobDispatcher.Dispatch(new FooJob
{
Data = new FooData
{
Id = 1
}
});
return Ok();
}
}
```
### Send Options ###
* **WaitToRetrySeconds:** Time as second for wait to retry when job rejects or throws an error. Should be greater then zero. Default 30 seconds.
* **ConfirmReceiptIsActive:** Set true if u want to wait to see the data received successfully from a worker until timeout. Otherwise can be false. It is highly recommended to be true. Default: true.
* **ConfirmReceiptTimeoutSeconds**: Wait until a dispatched data have been confirmed. Default 10 seconds.
```csharp
public void ConfigureServices(IServiceCollection services)
{
...
// Add Tossit Job dependencies with options.
services.AddTossitJob(sendOptions => {
sendOptions.WaitToRetrySeconds = 30;
sendOptions.ConfirmReceiptIsActive = true;
sendOptions.ConfirmReceiptTimeoutSeconds = 10;
});
...
}
```
## Worker Usage ##
Create new class to accept the data sent from jobs.
```csharp
public class FooData
{
public int Id { get; set; }
}
```
Create a new worker class to process given data.
```csharp
public class FooWorker : IWorker
{
public string JobName => "foo.job.name"; // Should be same as dispatched job name.
public bool Work(FooData data)
{
// Lets, do whatever you want by data.
// Return true, if working completed successfully, otherwise return false.
return true;
}
}
```
## License ##
The Tossit is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).