GithubHelp home page GithubHelp logo

bookbeat / knightbus Goto Github PK

View Code? Open in Web Editor NEW
22.0 10.0 5.0 1.18 MB

Fast multi-transport messaging framework

License: MIT License

C# 99.93% Shell 0.07%
servicebus azure-storage azure-service-bus middleware netstandard pubsub

knightbus's Introduction

KnightBus

Build status NuGet Documentation Status

KnightBus is a fast, lightweight and extensible messaging framework that supports multiple active message transports

Find the official KnightBus documentation here

KnightBus Logo

Transports

Package NuGet
KnightBus.Azure.ServiceBus KnightBus.Azure.ServiceBus
KnightBus.Azure.ServiceBus.Messages KnightBus.Azure.ServiceBus.Messages
KnightBus.Azure.ServiceBus.Management KnightBus.Azure.ServiceBus.Management
KnightBus.Azure.Storage KnightBus.Azure.Storage
KnightBus.Azure.Storage.Management KnightBus.Azure.Storage.Management
KnightBus.Azure.Storage.Messages KnightBus.Azure.Storage.Messages
KnightBus.Redis KnightBus.Redis
KnightBus.Redis.Messages KnightBus.Redis.Messages
KnightBus.Nats KnightBus.Nats
KnightBus.Nats.Messages KnightBus.Nats.Messages
KnightBus.PostgreSql KnightBus.PostgreSql
KnightBus.PostgreSql.Messages KnightBus.PostgreSql.Messages
KnightBus.PostgreSql.Management KnightBus.PostgreSql.Management

Monitoring

Package NuGet
KnightBus.ApplicationInsights KnightBus.ApplicationInsights
KnightBus.NewRelic KnightBus.NewRelic

Serialization

Package NuGet
KnightBus.ProtobufNet KnightBus.ProtobufNet
KnightBus.Newtonsoft KnightBus.Newtonsoft
KnightBus.MessagePack KnightBus.MessagePack

Framework

Package NuGet
KnightBus.Host KnightBus.Host
KnightBus.Core KnightBus.Core
KnightBus.Core.Management KnightBus.Core.Management
KnightBus.Messages KnightBus.Messages
KnightBus.SqlServer KnightBus.SqlServer
KnightBus.Schedule KnightBus.Schedule

Message Processing

public class CommandProcessor : IProcessCommand<SampleCommand, SampleSettings>,
{
    public CommandProcessor(ISomeDependency dependency)
    {
        //You can use your own container for dependency injection
    }

    public Task ProcessAsync(SampleCommand message, CancellationToken cancellationToken)
    {
        //Your code goes here
        return Task.CompletedTask;
    }
}

Initialization

class Program
{
    static async Task Main(string[] args)
    {
            var host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                //Multiple active transports
                services.UseServiceBus(config => config.ConnectionString = "sb-connection")
                        .UseTransport<ServiceBusTransport>()
                        .UseBlobStorage(config => config.ConnectionString = "storage-connection")
                        .UseTransport<StorageTransport>()
                        .RegisterProcessors();
            })
            .UseKnightBus().Build();                

            await host.StartAsync(CancellationToken.None);
    }
}

Bring your own Middleware

KnightBus supports inserting your own middleware into the execution pipeline.

public class CustomThrottlingMiddleware : IMessageProcessorMiddleware
    {
        private readonly SemaphoreQueue _semaphoreQueue;
        public int CurrentCount => _semaphoreQueue.CurrentCount;

        public CustomThrottlingMiddleware(int maxConcurrent)
        {
            _semaphoreQueue = new SemaphoreQueue(maxConcurrent);
        }
        public async Task ProcessAsync<T>(IMessageStateHandler<T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage
        {
            try
            {
                await _semaphoreQueue.WaitAsync().ConfigureAwait(false);
                await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false);
            }
            finally
            {
                _semaphoreQueue.Release();
            }
        }
    }

Write your own Plugin

KnightBus supports custom plugins. Examples of existing plugins are: TcpAliveListener (K8S liveness probes) and Scheduling (Chron triggers).

public class CustomPlugin : IPlugin
{
    public CustomPlugin(ISomeDependency dependency, ILogger<CustomPlugin> logger)
    {        
    }

    public async Task StartAsync(CancellationToken cancellationToken)
    {
        // Start the plugin
    }
}

Documentation

To get documentation up and running locally, do the following.

  1. Install sphinx: https://www.sphinx-doc.org
  2. Install sphinx_rtd_theme: https://github.com/readthedocs/sphinx_rtd_theme
  3. Run make html source build in the documentation folder
  4. Open documentation/build/html/index.html in a browser to preview your changes

For Linux:

# In documentation folder:

$ sudo apt install python3 python3-sphinx python3-pip
$ python3 -m pip install sphinx-rtd-theme
$ make html source build
$ sensible-browser build/html/index.html

knightbus's People

Contributors

albincarnstam avatar andrevirdarson avatar bjornbylund avatar bookbeatadmin avatar elmaxe avatar jjorbrand avatar johanssontobias avatar ludvigpaju avatar mbaneryd avatar nazgolgerholm1976 avatar niklasarbin avatar peterbergman avatar philiprominbookbeat avatar simonauner avatar tobiasbalzano avatar tobiasramnas avatar viktor-h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knightbus's Issues

Validate Dependencies and Scopes when building ServiceProvider

Currently, when using Microsofts Dependency injection framework, once we build our ServiceProvider we don't validate scopes or dependencies making it harder to catch eventual mistakes when registering dependencies.

This can be handled by passing custom ServiceProviderOptions new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true } when using .UseMicrosoftDependencyInjection but shouldn't this be the default behaviour?

Add backoff retry mechanism

Right now messages are retried as fast as they can be picked up. Allow backup to be configured per message and introduce a default. Remember to respect TTL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.