Kratos Transport

repository·main·Indexed 19 days ago

https://github.com/tx7do/kratos-transport

A unified transport and message broker extension set for the Kratos microservices framework. It provides a single abstraction layer supporting over 30 transport protocols, including message queues, RPC frameworks, and real-time communication protocols. It includes implementations for Azure Service Bus, GCP Pub/Sub, Kafka, and MQTT.

Tokens
236.6K
Snippets
973
Records
1.2K
Agent score
65%

What's inside kratos-transport

  1. What is Kratos Transport?

    main

    Kratos Transport is an integrated transport layer and message broker extension set designed for the Kratos microservices framework. It provides a unified abstraction layer covering over 30 transport protocols, including message queues, RPC frameworks, real-time communication protocols, and distributed task queues.

    Key features include:

    • Dual-Mode Integration: Implement transport.Server to register directly with the Kratos service lifecycle, or use the standalone broker.Broker interface for pure message proxy scenarios.
    • Type Safety: Leverages Go 1.18+ generics for APIs like TypedHandler[T], Subscribe[T], and RegisterSubscriber[S, T] to prevent runtime panics.
    • Unified Message Abstraction: Uses broker.Message to encapsulate Headers, Body, Metadata, Partition, and Offset, shielding your application from underlying protocol differences.
    • Observability: Built-in OpenTelemetry integration for full-link tracing across publish/subscribe operations.
    • Middleware Support: Bi-directional middleware chains for injecting cross-cutting concerns like logging, metrics, tracing, and rate limiting.
    • Modular Design: Each transport and broker implementation is an independent Go Module, allowing you to import only what you need and avoid dependency bloat.
  2. What is Hertz?

    main
    Hertz is a high-performance Golang microservice HTTP framework. It is designed to combine the advantages of frameworks like fasthttp, gin, and echo while providing high usability, high performance, and high extensibility. It is suitable for microservices that require high performance and significant customization capabilities.
  3. What is Machinery and its core features

    main

    Machinery is an open-source distributed asynchronous task queue for Go, similar to Python's Celery. It uses a producer-consumer model to handle task distribution and execution.

    Key Features:

    • Task retry mechanisms
    • Support for delayed tasks
    • Task callback mechanisms
    • Task result recording
    • Workflow orchestration modes: Chain, Group, and Chord
    • Supported Brokers (Message Queues): Redis, AMQP, AWS SQS
    • Supported Backends (Result Stores): Redis, Memcache, AMQP, MongoDB
  4. Overview of Asynq distributed task queue

    main

    Asynq is a distributed task queue and asynchronous processing library implemented in Go, built on top of Redis. It is conceptually similar to Python's Celery. It provides several key features for reliable task processing:

    • At-least-once execution guarantee: Ensures tasks are processed.
    • Persistence: Tasks are persisted in Redis once written.
    • Automatic Retries: Failed tasks are automatically retried.
    • Resilience: Workers automatically recover from crashes.
    • Task Management: Supports task prioritization, orchestration, scheduled execution, and maximum execution time limits.
    • Extensibility: Supports middleware and unique-option constraints to prevent duplicate task execution.
    • High Availability: Supports Redis Cluster and Redis Sentinel.
    • Observability: Provides a Web UI and CLI tool for monitoring task execution.
  5. Overview of the Iris web framework

    main

    Iris is a high-performance Go web framework designed for building web applications and microservices. It is characterized by its ability to run on various platforms (Android, iOS, Linux, Windows) with minimal resource consumption and is optimized for speed.

    Key features include:

    • High performance focus.
    • Robust static routing and wildcard subdomain support.
    • View system supporting over 5 template engines.
    • Extensible WebSocket API with custom events.
    • Session support with GC, memory, and Redis backends.
    • Middleware and plugin support.
    • Full REST API capabilities.
    • Customizable HTTP errors.
    • Automatic reloading after source code changes.
  6. Overview of Socket.IO transport

    main

    Socket.IO is a real-time communication library designed for real-time web applications, enabling bidirectional communication between servers and clients. While it primarily utilizes the WebSocket protocol, it provides fallback mechanisms (such as AJAX long-polling) to ensure connectivity in various environments.

    Key features include:

    • Bidirectional real-time communication.
    • Support for broadcasting to multiple sockets.
    • Ability to store data associated with different clients.
    • Support for asynchronous I/O operations.

    This transport implementation in kratos-transport is based on the go-socket.io engine.

  7. Overview of go-zero framework

    main

    go-zero is a web and RPC framework that integrates various engineering practices to ensure stability for high-concurrency services. It is designed to support services with tens of millions of daily active users.

    Key features include:

    • Built-in Microservice Governance: Includes cascaded timeout control, rate limiting, adaptive circuit breaking, and adaptive load shedding without requiring extra configuration or code.
    • Code Generation: Uses the goctl tool to generate runnable code for Go, iOS, Android, Kotlin, Dart, TypeScript, and JavaScript from minimal API definitions.
    • Automatic Validation: Automatically validates the legality of client request parameters.
    • Extensibility: Microservice governance middleware can be seamlessly integrated into other existing frameworks.
    • Tooling: Provides a large collection of microservice governance and concurrency toolkits.
  8. Overview of ActiveMQ capabilities

    main

    ActiveMQ is an open-source message bus from Apache that implements the JMS 1.1 and J2EE 1.4 specifications. It is designed for high-performance messaging and supports clustering.

    Key Features

    • JMS Support: Fully supports Java Message Service 1.1.
    • Multi-language Support: Compatible with C, C++, C#, Delphi, Erlang, Adobe Flash, Haskell, Java, JavaScript, Perl, PHP, Pike, Python, and Ruby.
    • Protocol Support: Supports OpenWire, REST, STOMP, WS-Notification, MQTT, XMPP, and AMQP.
    • Scalability: Supports clustering for distributed environments.
  9. Overview of the Gin HTTP framework

    main

    Gin is a high-performance HTTP web framework implemented in Go (Golang). It is designed for building RESTful APIs and web services with a focus on speed and minimal memory footprint.

    Key features include:

    • Fast Routing: Uses a Radix tree-based router that avoids reflection, ensuring high performance and low memory usage.
    • Middleware Support: Allows processing HTTP requests through a chain of middleware (e.g., Logger, Authorization, GZIP), similar to the Koa framework in Node.js. This mechanism enables high extensibility.
    • Robust Error Handling: Includes built-in mechanisms to catch and recover from panic to prevent service downtime, along with convenient error handling for HTTP requests.
    • JSON Support: Provides native capabilities to parse and validate JSON payloads, which is ideal for RESTful API development.
    • Route Grouping: Supports grouping routes (e.g., for versioning or applying specific authorization requirements to a set of endpoints) with support for nested groups without performance degradation.
    • Built-in Rendering: Natively supports rendering responses in JSON, XML, and HTML formats.
  10. Explore the project structure

    main

    The repository is organized into several core functional areas:

    • broker/: Contains the Broker interface and implementations for Kafka, MQTT, NATS, NSQ, Pulsar, RabbitMQ, Redis, RocketMQ, Azure Service Bus, GCP Pub/Sub, SQS, and STOMP.
    • transport/: Contains Transport Server extensions for various protocols and frameworks (e.g., Gin, Go-Zero, WebSocket, gRPC, Kafka, etc.).
    • tracing/: Provides distributed tracing extensions with multi-backend support.
    • _example/: Contains example projects for both brokers and servers.
    • testing/: Contains testing utilities.
  11. What is SignalR and when to use it

    main

    SignalR is a library that simplifies adding real-time web functionality to applications, allowing server-side code to push content to connected clients immediately. It provides a simple API for creating server-to-client Remote Procedure Calls (RPC) and manages connection lifecycles (connect/disconnect) and connection grouping.

    Use SignalR for:

    • High-frequency updates: Games, social networks, voting, auctions, maps, and GPS applications.
    • Dashboards and monitoring: Real-time sales updates, company dashboards, or trip alerts.
    • Collaborative applications: Whiteboard apps or team meeting software (e.g., simultaneous document editing).
    • Notifications: Social media alerts, email notifications, chat, and job progress updates.
  12. What is Server-Sent Events (SSE)?

    main

    Server-Sent Events (SSE) is a standard allowing servers to push real-time updates to clients over HTTP. Unlike WebSockets, which are full-duplex (bidirectional), SSE is a unidirectional (one-way) channel where data flows from the server to the client.

    Key characteristics of SSE:

    • Protocol: Uses standard HTTP, making it compatible with existing server software.
    • Simplicity: Lightweight and easier to implement than WebSockets.
    • Automatic Reconnection: Supports built-in reconnection logic.
    • Data Type: Primarily used for text/UTF-8 data (binary data requires encoding).
    • Custom Events: Supports custom event types that clients can listen for.