Giter Club home page Giter Club logo

rabbitmqpool's Introduction

rabbitmqPool

  • rabbitmq的客户端连接池
  • (使用rabbitmq文档提供的使用实例时,发现connection和channel没有实现复用,效率很低,由于一直没有找到实现connection和channel复用的相关代码库,故自己实现一个)
  • 在一台4核8G机子上ab压测http 10000次请求,1000并发时,qps为2000+。代码见https://github.com/Braveheart7854/asyncMessageSystem
  • 适当增大ConnectionNum和ChannelNum,可以提高性能

实现的功能

  • 可以设置client与rabbitmq服务端的connection池
  • 每个connection上建立的channel池
  • 每个connection与channel都有断线重连机制
  • 每个消息都有失败重试机制
  • 每个消息都有confirm机制,避免生产者消息丢失
  • 目前提供了生产者,而消费者后续会补上
  • 目前exchange的type类型默认是topic,没有支持其他三种类型,如果需要,请留言我给加上

依赖包

github.com/streadway/amqp

开始使用

  • go get github.com/lazy-tortoise/rabbitmqPool

  • 代码如下

rabbitmqPool.AmqpServer = rabbitmqPool.Service{
    AmqpUrl:"amqp://guest:guest@localhost:5672/",
    ConnectionNum:10,
    ChannelNum:100,
}
rabbitmqPool.InitAmqp()	
message,err := rabbitmqPool.AmqpServer.PutIntoQueue(ExchangeName,RouteKey,data)
if err != nil{
    //若有错误,则表示消息发送失败,做好失败消息处理
 	rabbitmqPool.Logger.Notice(message)
}

参考:

https://www.cnblogs.com/bigdataZJ/p/go-custom-pool.html

rabbitmqpool's People

Contributors

braveheart7854 avatar lazy-tortoise avatar lazytortoise avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.