Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cr-mao/rabbitmq
rabbitmq go client
https://github.com/cr-mao/rabbitmq
go-common-pool go-conn-pool go-rabbitmq rabbitmq rabbtimq-client
Last synced: 6 days ago
JSON representation
rabbitmq go client
- Host: GitHub
- URL: https://github.com/cr-mao/rabbitmq
- Owner: cr-mao
- Created: 2024-04-27T07:12:07.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-27T07:17:50.000Z (7 months ago)
- Last Synced: 2024-04-27T08:24:12.551Z (7 months ago)
- Topics: go-common-pool, go-conn-pool, go-rabbitmq, rabbitmq, rabbtimq-client
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## golang rabbitmq client
golang 操作 rabbitmq封装
- 带有连接池实现(单连接在高并发项目下,是不够用的)
- 统一使用topic模式,通用能覆盖所有场景。```shell
go get github.com/cr-mao/rabbitmq
```### example
消费者
```go
package main
import (
"github.com/cr-mao/rabbitmq"
)
const bindClient string ="default"func main() {
ctx := context.Background()
//
var bindDsn = map[string]string{
bindClient: "amqp://admin:[email protected]:5672/",
}
rabbitmq.Init(bindDsn, 10)
var consumer = &rabbitmq.AMQPConsumer{
Bind: bindClient,
Subscription: &rabbitmq.Subscription{
Exchange: "testexchange",
Queue: "testqueue",
Key: []string{
"test",
},
},
MessageHandler: func(ctx context.Context, msg []byte) error {
fmt.Println(string(msg))
return nil
},
}
err := consumer.Run(ctx)
if err != nil {
fmt.Println(err)
}
}
```生产者:
```go
package main
import (
"github.com/cr-mao/rabbitmq"
)const bindClient string ="default"
func main(){
var bindDsn = map[string]string{
bindClient: "amqp://admin:[email protected]:5672/",
}
rabbitmq.Init(bindDsn, 10)
ctx := context.Background()
rabbitmq.Pub(ctx, bindClient, "testexchange", "test", []byte("cr-mao"))
}
```### links
[golang通用连接池](github.com/jolestar/go-commons-pool/v2)