The networks core of the Minos Framework providing networking components for reactive microservices
—
The routing system provides abstract interfaces and concrete implementations for handling different types of route registration and management. Routers aggregate decorated handlers and provide structured access to routing information across different transport types.
Abstract base class that defines the routing contract for all transport types.
from abc import ABC, abstractmethod
from typing import Dict, List, Callable
class Router(ABC):
routes: Dict[Any, Callable]
@abstractmethod
def build_routes(self) -> None: ...
def get_routes(self) -> Dict[Any, Callable]: ...Usage Examples:
from minos.networks import Router
# Routers are typically used internally by the framework
# They aggregate decorated handlers automaticallyRouter implementation for message broker handlers, collecting broker-decorated methods.
class BrokerRouter(Router):
def __init__(self): ...
routes: Dict[BrokerEnrouteDecorator, Callable]
def build_routes(self) -> None: ...Usage Examples:
from minos.networks import BrokerRouter, enroute
class MessageService:
@enroute.broker.command("user.create")
async def create_user(self, request):
return Response({"status": "created"})
# Router automatically discovers and manages broker routes
broker_router = BrokerRouter()
broker_router.build_routes()Router implementation for HTTP handlers, managing REST endpoint registration.
class HttpRouter(Router):
def __init__(self): ...
routes: Dict[HttpEnrouteDecorator, Callable]
def build_routes(self) -> None: ...Specialized HTTP router for RESTful service endpoints.
class RestHttpRouter(HttpRouter):
def __init__(self): ...
routes: Dict[RestEnrouteDecorator, Callable]
def build_routes(self) -> None: ...Usage Examples:
from minos.networks import RestHttpRouter, enroute
class UserAPI:
@enroute.rest.query("/users/{user_id}", method="GET")
async def get_user(self, request):
return Response({"id": "123", "name": "John"})
@enroute.rest.command("/users", method="POST")
async def create_user(self, request):
return Response({"id": "456"}, status=201)
# Router manages REST endpoint registration
rest_router = RestHttpRouter()
rest_router.build_routes()Router implementation for scheduled/periodic task handlers.
class PeriodicRouter(Router):
def __init__(self): ...
routes: Dict[PeriodicEnrouteDecorator, Callable]
def build_routes(self) -> None: ...Usage Examples:
from minos.networks import PeriodicRouter, enroute
class ScheduledTasks:
@enroute.periodic.event("0 */5 * * * *") # Every 5 minutes
async def cleanup_task(self, request):
# Perform cleanup
return Response({"status": "cleanup_completed"})
@enroute.periodic.event("0 0 * * * *") # Every hour
async def hourly_report(self, request):
return Response({"report": "generated"})
# Router manages periodic task registration
periodic_router = PeriodicRouter()
periodic_router.build_routes()Routers work together with the decorator system and ports to provide comprehensive routing:
The routing system enables the framework's unified decorator approach while maintaining clean separation between different transport mechanisms.
Install with Tessl CLI
npx tessl i tessl/pypi-minos-microservice-networks