https://github.com/gregyjames/requeue
C# Library to use a redis list for messaging.
https://github.com/gregyjames/requeue
ampq async asyncronous asyncronous-messaging cache messaging redis
Last synced: 2 months ago
JSON representation
C# Library to use a redis list for messaging.
- Host: GitHub
- URL: https://github.com/gregyjames/requeue
- Owner: gregyjames
- License: mit
- Created: 2024-02-18T05:14:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-19T03:22:40.000Z (about 1 year ago)
- Last Synced: 2024-05-01T18:23:56.131Z (about 1 year ago)
- Topics: ampq, async, asyncronous, asyncronous-messaging, cache, messaging, redis
- Language: C#
- Homepage: https://www.nuget.org/packages/ReQueue/
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/gregyjames/ReQueue/actions/workflows/dotnet.yml)

# ReQueue
C# Library to use a redis list for asynchronous messaging. Perfect for small projects you don't want to set up RabbitMQ for. Try using it with a fast redis implemetation like [Dragonfly](https://github.com/dragonflydb/dragonfly).# Example
## Object
The library uses MessagePack under the hood, so make sure your object is marked as MessagePack serilizable.
```csharp
[MessagePackObject(keyAsPropertyName: true)]
public class Data
{
public int Foo { get; set; }
}
```## Producer
```csharp
internal class Program
{
static async Task Main(string[] args)
{
var manager = new ConnectionHub("localhost", 0);
var queue = manager.GetMessageQueue("numQueue");for (int i = 0; i < 100; i++)
{
var item = new Data { Foo = i };
await queue.EnqueueMessages(item);
Console.WriteLine($"Sending -> {i}");
}Console.ReadLine();
}
}
```## Consumer
```csharp
internal class Program
{
static async Task Main(string[] args)
{
var manager = new ConnectionHub("localhost", 0);
var queue = manager.GetMessageQueue("numQueue");
var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromDays(6));await queue.DequeueMessages(x => {
Console.WriteLine($"Recieved -> {x.Foo}");
}, tokenSource.Token);
Console.ReadLine();
}
}
```
## Filter Example
Filters out messages that don't meet set criteria. By default, messages that are filtered out will be readded to the end of the queue.
```csharp
queue.DequeueMessages(x => {
Console.WriteLine($"Recieved -> {x.Foo}");
}, tokenSource.Token, data => {
if (data.Foo % 2 == 0){
return true;
}
return false;
});
```
# License
MIT LicenseCopyright (c) 2024 Greg James
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.