CloudWeGo-Kitex Documentation

repository·main·Indexed 27 days ago

https://github.com/cloudwego/kitex

A high-performance, extensible Go RPC framework optimized for microservices. It leverages the Netpoll network library and supports multiple protocols including Thrift, gRPC, and Kitex Protobuf. The framework provides tools for service discovery via the ServiceSearcher interface, customizable retry policies, and support for both unary and streaming communication.

Tokens
12.2K
Snippets
11
Records
120
Agent score
93%

What's inside CloudWeGo-Kitex

  1. Overview of CloudWeGo-Kitex

    main

    CloudWeGo-Kitex is a high-performance, highly extensible Go microservice RPC framework developed by ByteDance. It is designed for high-performance requirements and allows developers to customize and integrate their own service governance systems.

    Key Features:

    • High Performance: Uses the Netpoll high-performance network library by default.
    • Extensibility: Provides numerous extension interfaces and default implementations for custom governance.
    • Multi-Protocol Support: Supports Thrift (Buffered and Framed), Kitex Protobuf, and gRPC (interoperable with standard gRPC).
    • Multi-Transport Support: Supports TTHeader (can be used with Thrift and Kitex Protobuf) and HTTP2.
    • Message Types: Supports PingPong, Oneway (Thrift only), and Bidirectional Streaming.
    • Service Governance: Built-in support for service registration/discovery, load balancing, circuit breaking, rate limiting, retries, monitoring, tracing, logging, and diagnostics.
    • Code Generation: Built-in tools for generating Thrift, Protobuf, and scaffolding code.
  2. Use bthrift/apache for legacy Apache Thrift compatibility

    main
    If you are working with legacy generated code that relies on Apache Thrift, use bthrift/apache to access necessary types, interfaces, and constants. This package contains moved Apache dependencies to reduce direct reliance on github.com/apache/thrift.
  3. Migrate Invocation and InvocationSetter interfaces (v0.15.0)

    main

    In v0.15.0, new methods were added to the rpcinfo interfaces to handle method information.

    Changes:

    • Invocation interface now includes MethodInfo() serviceinfo.MethodInfo.
    • InvocationSetter interface now includes SetMethodInfo(serviceinfo.MethodInfo).
    • InvocationServiceInfoKey is a new extra key available.

    Migration: Implement these new methods on all custom Invocation and InvocationSetter implementations.

  4. Migrate Thrift Codec in Kitex v0.12.0

    main

    In Kitex v0.12.0, several deprecated interfaces and types in codec/thrift were removed.

    • Remove: MessageReader, MessageWriter, BinaryProtocol (type alias), NewBinaryProtocol, and UnmarshalThriftException.
    • Migration: Use github.com/cloudwego/gopkg/protocol/thrift instead.
    • Deprecation: ThriftMsgFastCodec is deprecated. Use github.com/cloudwego/gopkg/protocol/thrift.FastCodec directly.
  5. Migrate remote Message interface (v0.15.0)

    main

    In v0.15.0, the Message interface was changed to remove service and protocol information.

    Changes:

    • NewMessage(data, svcInfo, ri, msgType, rpcRole) is now NewMessage(data, ri, msgType, rpcRole).
    • NewMessageWithNewer has been removed.
    • The following methods were removed from the Message interface: ServiceInfo(), SpecifyServiceInfo(), ProtocolInfo(), and SetProtocolInfo().
    • The ProtocolInfo struct and NewProtocolInfo function were removed.
    • The FillSendMsgFromRecvMsg function was removed.

    Migration: Instead of using the Message interface for service information, resolve service info via rpcinfo instead.

  6. Explore Kitex Documentation and Guides

    main

    Kitex provides comprehensive documentation categorized by user needs:

    • Getting Started: Quick Start Guide
    • Basic Features: Learn about message types, codec protocols, direct access, connection pools, timeout control, retries, load balancing, circuit breaking, and logging.
    • Service Governance: Documentation on service discovery, monitoring, tracing, and custom access control.
    • Advanced Features: Information on generic calls and Server SDK capabilities.
    • Code Generation: Instructions for using the code generation tools and Combine Service.
    • Framework Extensions: Detailed guides on implementing custom Middleware, Suite extensions, service discovery, load balancing, monitoring, logging, and more.
    • Best Practices: Production-ready guidance on graceful shutdown, error handling, and integration testing.
    • Reference: Technical details on the TTHeader application layer transport protocol, exception handling, and version management.
  7. Migrate ServiceInfo and GenericMethod (v0.15.0)

    main

    In v0.15.0, several serviceinfo components were updated to support context.Context.

    Changes:

    • ServiceInfo.MethodInfo(name string) is now ServiceInfo.MethodInfo(ctx context.Context, name string).
    • ServiceInfo.GenericMethod type changed from func(name string) MethodInfo to GenericMethodFunc, which is func(ctx context.Context, methodName string) MethodInfo.
    • GenericClientStreamingMethod, GenericServerStreamingMethod, and GenericBidirectionalStreamingMethod were removed.
    • New fields added: PackageName, CombineServiceKey, and CombineServiceName.
  8. Migrate Descriptor Type Mapping in Kitex v0.12.0

    main

    In Kitex v0.12.0, the signature for descriptor.FromThriftTType changed.

    • Old: descriptor.FromThriftTType(t thrift.TType) Type
    • New: descriptor.FromThriftTType(v interface{}) Type
    • Migration: Use descriptor.Type(t) instead.
  9. Handle unknown service/method traffic with genericserver V2

    main

    In v0.15.0, server.WithGeneric(g) is deprecated. Use generic.BinaryThriftGenericV2 or the new genericserver API to handle unknown service/method traffic.

    New APIs in genericserver:

    • genericserver.NewServerV2(handler, g, opts...)
    • genericserver.RegisterService(svr, handler, g, opts...)
    • genericserver.RegisterUnknownServiceOrMethodHandler(svr, handler)
    • genericserver.NewUnknownServiceOrMethodServer(handler, opts...)

    These use the UnknownServiceOrMethodHandler struct to manage traffic for undefined services or methods.

  10. Migrate genericclient streaming (v0.15.0)

    main

    In v0.15.0, ClientStreamingClient, ServerStreamingClient, and BidiStreamingClient no longer embed streaming.ClientStream.

    Migration: Use the following explicit methods or the new Streaming() method to access the underlying stream:

    • Header()
    • Trailer()
    • CloseSend()
    • Context()
    • Streaming() streaming.ClientStream
  11. Migrate Generic ServiceInfo in Kitex v0.12.0

    main

    In Kitex v0.12.0, the following changes were made to the generic package:

    • Remove: generic.ServiceInfo(pcType) (deprecated since v0.11.0).
    • Migration: Use generic.ServiceInfoWithGeneric(g) instead.
    • Remove: generic.DeprecatedGenericServiceInfoAPIKey constant.
    • Type Aliases: generic.Args and generic.Result are now type aliases.