Code Monkey home page Code Monkey logo

astral's Introduction

Astral

Included libraries:

  • Astral.Core - base interfaces, extensions and Result and Option monad for .Net
  • Astral.Markup - attribute based .net service markup
  • Astral.Schema - service schema builder and AST
  • Astral - utility library for service integration
  • Astral.RabbitLink - service bus realisation for RabbitLink (RabbitMq based)

Usage.

Decalare service.

[Owner("main")]
[Service("orders")]
public interface IOrderService
{
    [Endpoint("order.changed")] 
    EventHandler<Order> OrderChanged { get; }
    
    [Endpoint("order.create")]
    Func<Order, int> CreateOrder { get; }
    
    [Endpoint("order.update")]
    Action<Order> UpdateOrder { get; }
}

[Contract("order")]
public class Order
{
    public int Number { get; set; }
    public string Customer { get; set; }
    public List<OrderLine> Lines { get; set; }
}

public class OrderLine
{
    public string GoodCode { get; set; }
    public double Quantity { get; set; }
    public double Price { get; set; }
}

RabbitMq behavior

  • OrderChanged - Exchange name "main.orders", exchange type - direct, routing key "order.changed", message type - "order", message content type - "text/json;charset-utf-8"
  • CreateOrder - Request exchange name "main.orders", exchange type - direct, routing key "order.create", message type - "order", message content type - "text/json;charset-utf-8", response exchange name "main.orders", request queue name - "main.orders.order.create"
  • UpdateOrder - Request exchange name "main.orders", exchange type - direct, routing key "order.update", message type - "order", message content type - "text/json;charset-utf-8", response exchange name "main.orders", request queue name - "main.orders.order.update"

RabbitMq customization:

Attribute based:

  • ExchangeAttribute - specify exchange parameters
  • ResponseExchange - specify response exchange parameters
  • RpcQueueAttribute - specify request queue parameters
  • RoutingKeyAttribute - specify routing key

Server usage.

using (var link =
            new ServiceLinkBuilder()
                .HolderName("testserver")
                .Uri("amqp://localhost")
                .AutoStart(true)
                .ConnectionName("Test process")
                .Build())
{
    link.Service<IOrderService>().Call(p => p.CreateOrder)
        .Process((order, cancellation) => Task.FromResult(25));  
    link.Service<IOrderService>().Event(p => p.OrderChanged)
        .PublishAsync(new Order { Numder = 25 });
    Console.ReadKey();    
}

Client usage.

using (var link =
            new ServiceLinkBuilder()
                .HolderName("testclient")
                .Uri("amqp://localhost")
                .AutoStart(true)
                .ConnectionName("Test process")
                .Build())
{
    var id = await link.Service<IOrderService>().Call(p => p.CreateOrder)
        .Call(new Order { Numder = 25 });  
    link.Service<IOrderService>().Event(p => p.OrderChanged)
        .Listen((order, cancellation) => Console.WriteLine($"Order {order.Numder} has been changed");
    
    Console.ReadKey();    
}

astral's People

Contributors

ijsgaus avatar

Watchers

James Cloos avatar  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.