https://github.com/goapt/nsqclient
nsq client for golang
https://github.com/goapt/nsqclient
Last synced: 8 months ago
JSON representation
nsq client for golang
- Host: GitHub
- URL: https://github.com/goapt/nsqclient
- Owner: goapt
- License: mit
- Created: 2018-06-26T09:58:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-19T09:57:26.000Z (about 3 years ago)
- Last Synced: 2025-03-26T10:16:00.195Z (about 1 year ago)
- Language: Go
- Size: 63.5 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nsqclient
nsq client for golang
## Connection
```go
nsqclient.Connect(map[string]Config{
"default": Config{
Host: "10.64.146.231",
Port: "4150",
InitSize: 10,
MaxSize: 10,
},
"other": Config{
Host: "10.64.146.22",
Port: "4150",
InitSize: 10,
MaxSize: 10,
},
})
```
## Publish
写入nsq为了方便进行单元测试,可以注入nsqclient.Producer接口,然后在单元测试使用mock的实现
```go
// default client
nsq := nsqclient.NewProducer("default")
nsq.Publish("topic","body")
//mock
nsq := nsqclient.NewMockProducer("default")
nsq.Publish("topic","body")
```
## Consumer
```go
// default connect
consumer := &nsqclient.NsqHandler{
Topic: "log",
Channel: "default",
Size: 10,
}
consumer.SetHandle(func(lg logger.ILogger, message *nsq.Message) error {
// something
return nil
})
nsqclient.Register(consumer, "access_log")
nsqclient.Run("access_log", ctx)
// other connect
consumer := &nsqclient.NsqHandler{
Connect: "other",
Topic: "log",
Channel: "default",
Size: 10,
}
```