Documentation
¶
Overview ¶
Example (Kafka) ¶
var sub = NewKafkaSubscriber(context.Background(), KafkaConfig{ Hosts: []string{"localhost:3096"}, PartitionID: 0, Topic: "topic-test", }) _ = sub.Run() defer sub.Close() messageChan, _ := sub.Get() for message := range messageChan { var m Message _ = json.Unmarshal(message, &m) }
Output:
Example (Ws) ¶
var sub = NewWsSubscriber(context.Background(), WsConfig{ Addr: "localhost:8080", Path: "/ws-test", }) _ = sub.Run() defer sub.Close() messageChan, _ := sub.Get() for message := range messageChan { var m Message _ = json.Unmarshal(message, &m) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FakeConfig ¶
type FakeConfig struct {
PublishSend <-chan []byte
}
type KafkaConfig ¶
type Subscribe ¶
type Subscribe interface { // Get use key to recognize messages what I need. // Note that data is recommended to design into a struct include a string key and a bytes type data. Get() (<-chan []byte, error) Run() error Close() error }
func NewFakeSubscriber ¶
func NewFakeSubscriber(config FakeConfig) Subscribe
func NewKafkaSubscriber ¶
func NewKafkaSubscriber(ctx context.Context, config KafkaConfig) Subscribe
Click to show internal directories.
Click to hide internal directories.