tx7do / kratos-transport

kratos transport layer extension
MIT License
348 stars 95 forks source link

FR: `kafka.Server` 添加一个 option 进来,传入 `broker.Broker` #75

Closed fzdwx closed 9 months ago

fzdwx commented 9 months ago

示例代码:

func WithBroker(b broker.Broker) ServerOption {
    return func(s *Server) {
        s.Broker = b
    }
}

func NewServer(opts ...ServerOption) *Server {
    srv := &Server{
        ...
    }

    srv.doInjectOptions(opts...)

    if srv.Broker == nil {
        srv.Broker = kafka.NewBroker(srv.brokerOpts...)
    }

    return srv
}

原因:

一个服务可能同时生产消息与消费消息,复用同一个 broker。

tx7do commented 9 months ago

怎么能这样呢?

fzdwx commented 9 months ago

怎么不能呢? 😭

tx7do commented 9 months ago

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

我这里应该有相关的应用。你看看。