Git Product home page Git Product logo

lagomorpha's Introduction

Lagomorpha

Library to abstract the message consumption from RabbitMQ for .NET Core.

The rabbit comes from the family Lagomorpha.

Usage

  • Include this package in your project, using this command in your Package Manager Console:
    Install-Package Lagomorpha

  • In your .NET Core section to configuration of services, include, passing one type of the assembly where the handlers will be located:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddLagomorpha(config =>
    {
        config.UseRabbitMQ()
              .WithDefaultAssembly(typeof(Startup).Assembly)
              .WithUri("") // You can configure by uri or separated data, as below...
              .WithHost("localhost")
              .WithPort(26001)
              .WithUsername("root")
              .WithPassword("!root");
    });
    
    // Some other dependencies
    
    services.AddMvc();
}
  • Create some class to handle your messages:
  • You can also declare dependencies in the constructor, Lagomorpha uses the default Dependency Injection provider to create the class, so, your depencency must be declared in your DI provider.
public class MessageHandler 
{
    private readonly ISomeDependency _dep;
    
    public MessageHandler(ISomeDependency dep) 
    {
        _dep = dep;
    }

    [QueueHandler("NewProductQueue")]
    public void HandleNewProduct(Product p)
    {
        _dep.DoSomething(p);    
    }
    
    // You can have multiple handlers for the same queue and specify the handlers order
    [QueueHandler("NewProductQueue", Order = 2)]
    public void HandleNewProductTwo(Product p)
    {
        _dep.DoSomething(p);    
    }
}
  • Add this handler to de Dependency Injection service:
public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddScoped<MessageHandler>();
    services.AddMvc();
}
  • And that's all! :D

Lagomorpha will handle new messages in the queue called NewProductQueue, and cast the incoming messages to the class Product, the first method's parameter.

lagomorpha's People

Contributors

gustavoosantoos avatar

Watchers

 avatar

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.