https://github.com/blackbeans/kiteq-client-go
kiteq-client-go is kiteq's go client
https://github.com/blackbeans/kiteq-client-go
Last synced: 4 months ago
JSON representation
kiteq-client-go is kiteq's go client
- Host: GitHub
- URL: https://github.com/blackbeans/kiteq-client-go
- Owner: blackbeans
- Created: 2016-03-10T08:20:18.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-05-18T16:12:13.000Z (about 3 years ago)
- Last Synced: 2024-06-19T20:53:11.799Z (almost 2 years ago)
- Language: Go
- Size: 136 KB
- Stars: 9
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kiteq-client-go
kiteq-client-go is kiteq's go client
#### 工程结构
kiteq/
├── README.md
├── log log4go的配置
├── benchmark KiteQ的Benchmark程序
├── client KiteQ的客户端
##### 启动客户端:
```
对于KiteQClient需要实现消息监听器,我们定义了如下的接口:
type IListener interface {
//接受投递消息的回调
OnMessage(msg *protocol.StringMessage) bool
//接收事务回调
// 除非明确提交成功、其余都为不成功
// 有异常或者返回值为false均为不提交
OnMessageCheck(tx *protocol.TxResponse) error
}
启动Producer :
producer := client.NewKiteQClient(${zkhost}, ${groupId}, ${password}, &defualtListener{})
producer.SetTopics([]string{"trade"})
producer.Start()
//构建消息
msg := &protocol.StringMessage{}
msg.Header = &protocol.Header{
MessageId: proto.String(client.MessageId()),
Topic: proto.String("trade"),
MessageType: proto.String("pay-succ"),
ExpiredTime: proto.Int64(time.Now().Unix()),
DeliveryLimit: proto.Int32(-1),
GroupId: proto.String("go-kite-test"),
Commit: proto.Bool(true)}
msg.Body = proto.String("echo")
//发送消息
producer.SendStringMessage(msg)
启动Consumer:
consumer:= client.NewKiteQClient(${zkhost}, ${groupId}, ${password}, &defualtListener{})
consumer.SetBindings([]*binding.Binding{
binding.Bind_Direct("s-mts-test", "trade", "pay-succ", 1000, true),
})
consumer.Start()
```
Bingo 完成发布和订阅消息的功能了.....
- 可以参考benchmark中使用