SlideShare uma empresa Scribd logo
1 de 38
Taste
    jeff@techparty.org
What‘s a MQ
What‘s a MQ




     queue
What‘s a MQ

message




          queue
What‘s a MQ

           message



Producer

                     queue
What‘s a MQ
                             Consumer

           message



Producer

                     queue
Why MQ


De-couple

Higher performance

Another IPC
Why rabbitMQ?
Based on Erlang

  Reliable

  Highly available

  Scalable

  portable

Implemented AMQP Standard and More

100% OpenSource
I have a log system
register                Login




logout




                    Log System




                                         DataBase
register                Login
                                         log = getLog(request)
                                         if log.type == ‘login’:
logout                                      # balabala .......
                                         if log.type == ‘register’:
                                            # balabala .......
                                         log.save()
                    Log System




                                             DataBase
register                Login
                                              log = getLog(request)
                                              if log.type == ‘login’:
     logout                                      # balabala .......
                                              if log.type == ‘register’:
                                                 # balabala .......
                                              log.save()
                         Log System




I need ...
1. better performance
2. cleaner code                                   DataBase


3. easier to test
4. ....
Step1. work with Queue
Step1. work with Queue
.......
log = getLog(request)
channel.publish(None,‘log-queue’,None,log)
Step1. work with Queue
.......
log = getLog(request)
channel.publish(None,‘log-queue’,None,log)




                                         def onLog(log):
                                           if log.type == ‘login’:
                                              # balabala
                                           if log.type == ‘logout’:
                                              # balabala
                                           log.save()
Step1. work with Queue
.......
log = getLog(request)
channel.publish(None,‘log-queue’,None,log)




                                         def onLog(log):
                                           if log.type == ‘login’:
                                              # balabala
                                           if log.type == ‘logout’:
                                              # balabala
                                           log.save()
Step1. work with Queue
.......
log = getLog(request)
channel.publish(None,‘log-queue’,None,log)




                                         def onLog(log):
                                           if log.type == ‘login’:
yep. performance better now                   # balabala
but. that                                  if log.type == ‘logout’:
codes still smell bad~~                       # balabala
                                           log.save()
step2. Split Queues



       login




      logout
step2. Split Queues
.......
log = getLog(request)
channel.publish(None,log.type,None,log)



                            login




                           logout
step2. Split Queues
.......                                   def onLog(loginlog):
log = getLog(request)                       # balabala
channel.publish(None,log.type,None,log)     loginlog.save()



                            login




                           logout
step2. Split Queues
.......                                   def onLog(loginlog):
log = getLog(request)                       # balabala
channel.publish(None,log.type,None,log)     loginlog.save()



                            login




                           logout

                                          def onLog(logoutlog):
                                            # balabala
                                            logoutlog.save()
step2. Split Queues
.......                                   def onLog(loginlog):
log = getLog(request)                       # balabala
channel.publish(None,log.type,None,log)     loginlog.save()



                            login




                           logout

                                          def onLog(logoutlog):
                                            # balabala
What’s that guy?
                                            logoutlog.save()
Say hi to Exchange
Direct Exchange
Fanout Exchange
Topic Exchange
step3. Share message


                     c#
        x
       login         c1
P

        x
                     c2
       logout
step3. Share message
.......
log = getLog(request)
channel.exchange_declare(log.type,‘fanout’)
channel.publish(log.type,’’,None,log)

                                              c#
                  x
                 login                        c1
      P

                  x
                                              c2
                 logout
step3. Share message
.......
log = getLog(request)                         def onLog(loginlog):
channel.exchange_declare(log.type,‘fanout’)     # balabala
channel.publish(log.type,’’,None,log)           loginlog.save()

                                                  c#
                  x
                 login                             c1
      P

                  x
                                                   c2
                 logout
step3. Share message
.......
log = getLog(request)                         def onLog(loginlog):
channel.exchange_declare(log.type,‘fanout’)     # balabala
channel.publish(log.type,’’,None,log)           loginlog.save()

                                                  c#
                  x
                 login                             c1
      P

                  x
                                                   c2
                 logout
                                              def onLog(logoutlog):
                                                # balabala
                                                logoutlog.save()
Performance test
     non-persist-mode
     100000 msg

                 en-queue      de-queue
     10,000/s

      7,500/s

      5,000/s

      2,500/s

          0/s
                128   512 1024 3072 10240
Performance tune


Parameters for multiple consumer toning:

  QOS

  consumer count

  autoAck?
clustering to scale
Start rabbit nodes:

rabbit1$ rabbitmq-server

rabbit2$ rabbitmq-server
clustering to scale
create cluster:
rabbit2$ rabbitmqctl stop_app
Stopping node rabbit@rabbit2 ...done.

rabbit2$ rabbitmqctl reset
Resetting node rabbit@rabbit2 ...done.

rabbit2$ rabbitmqctl cluster rabbit@rabbit1
Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done.

rabbit2$ rabbitmqctl start_app
Starting node rabbit@rabbit2 ...done.
clustering to scale
Check it out:

rabbit1$ rabbitmqctl status
Status of node rabbit@rabbit1 ...
[...,
  {nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]},
  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}]
...done.
Highly Available
discuss ......
Thank you


http://jeffkit.info

http://twitter.com/jeff_kit

jeff@techparty.org

Mais conteúdo relacionado

Destaque

High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQ
James Carr
 

Destaque (19)

Erlang scheduler
Erlang schedulerErlang scheduler
Erlang scheduler
 
redis 适用场景与实现
redis 适用场景与实现redis 适用场景与实现
redis 适用场景与实现
 
Redis介绍
Redis介绍Redis介绍
Redis介绍
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal Labs
 
RabbitMQ Messaging
RabbitMQ MessagingRabbitMQ Messaging
RabbitMQ Messaging
 
Integrating RabbitMQ with PHP
Integrating RabbitMQ with PHPIntegrating RabbitMQ with PHP
Integrating RabbitMQ with PHP
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHP
 
RabbitMQ fairly-indepth
RabbitMQ fairly-indepthRabbitMQ fairly-indepth
RabbitMQ fairly-indepth
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft Conf
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
深入了解Redis
深入了解Redis深入了解Redis
深入了解Redis
 
RabbitMQ Operations
RabbitMQ OperationsRabbitMQ Operations
RabbitMQ Operations
 
High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQ
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQ
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to ask
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 

Semelhante a Taste Rabbitmq

Java Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4jJava Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4j
Rajiv Gupta
 
Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012
Bip Thelin
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 

Semelhante a Taste Rabbitmq (13)

Java Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4jJava Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4j
 
Functional python
Functional pythonFunctional python
Functional python
 
World of Logging
World of LoggingWorld of Logging
World of Logging
 
Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechture
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
 
Python 3
Python 3Python 3
Python 3
 
Jvm internals
Jvm internalsJvm internals
Jvm internals
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 

Mais de jeff kit (11)

构建稳健的iOS推送服务
构建稳健的iOS推送服务构建稳健的iOS推送服务
构建稳健的iOS推送服务
 
冲浪 Object-c
冲浪 Object-c冲浪 Object-c
冲浪 Object-c
 
给Geek们的音乐课
给Geek们的音乐课给Geek们的音乐课
给Geek们的音乐课
 
漫游iOS开发指南
漫游iOS开发指南漫游iOS开发指南
漫游iOS开发指南
 
Scala jeff
Scala jeffScala jeff
Scala jeff
 
原创音乐会
原创音乐会原创音乐会
原创音乐会
 
杯具是怎样练成的
杯具是怎样练成的杯具是怎样练成的
杯具是怎样练成的
 
Bi
BiBi
Bi
 
Git
GitGit
Git
 
Autoforms
AutoformsAutoforms
Autoforms
 
Brief intro of Dropbox
Brief intro of DropboxBrief intro of Dropbox
Brief intro of Dropbox
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Taste Rabbitmq

  • 1. Taste jeff@techparty.org
  • 5. What‘s a MQ message Producer queue
  • 6. What‘s a MQ Consumer message Producer queue
  • 8. Why rabbitMQ? Based on Erlang Reliable Highly available Scalable portable Implemented AMQP Standard and More 100% OpenSource
  • 9. I have a log system
  • 10. register Login logout Log System DataBase
  • 11. register Login log = getLog(request) if log.type == ‘login’: logout # balabala ....... if log.type == ‘register’: # balabala ....... log.save() Log System DataBase
  • 12. register Login log = getLog(request) if log.type == ‘login’: logout # balabala ....... if log.type == ‘register’: # balabala ....... log.save() Log System I need ... 1. better performance 2. cleaner code DataBase 3. easier to test 4. ....
  • 14. Step1. work with Queue ....... log = getLog(request) channel.publish(None,‘log-queue’,None,log)
  • 15. Step1. work with Queue ....... log = getLog(request) channel.publish(None,‘log-queue’,None,log) def onLog(log): if log.type == ‘login’: # balabala if log.type == ‘logout’: # balabala log.save()
  • 16. Step1. work with Queue ....... log = getLog(request) channel.publish(None,‘log-queue’,None,log) def onLog(log): if log.type == ‘login’: # balabala if log.type == ‘logout’: # balabala log.save()
  • 17. Step1. work with Queue ....... log = getLog(request) channel.publish(None,‘log-queue’,None,log) def onLog(log): if log.type == ‘login’: yep. performance better now # balabala but. that if log.type == ‘logout’: codes still smell bad~~ # balabala log.save()
  • 18. step2. Split Queues login logout
  • 19. step2. Split Queues ....... log = getLog(request) channel.publish(None,log.type,None,log) login logout
  • 20. step2. Split Queues ....... def onLog(loginlog): log = getLog(request) # balabala channel.publish(None,log.type,None,log) loginlog.save() login logout
  • 21. step2. Split Queues ....... def onLog(loginlog): log = getLog(request) # balabala channel.publish(None,log.type,None,log) loginlog.save() login logout def onLog(logoutlog): # balabala logoutlog.save()
  • 22. step2. Split Queues ....... def onLog(loginlog): log = getLog(request) # balabala channel.publish(None,log.type,None,log) loginlog.save() login logout def onLog(logoutlog): # balabala What’s that guy? logoutlog.save()
  • 23. Say hi to Exchange
  • 27. step3. Share message c# x login c1 P x c2 logout
  • 28. step3. Share message ....... log = getLog(request) channel.exchange_declare(log.type,‘fanout’) channel.publish(log.type,’’,None,log) c# x login c1 P x c2 logout
  • 29. step3. Share message ....... log = getLog(request) def onLog(loginlog): channel.exchange_declare(log.type,‘fanout’) # balabala channel.publish(log.type,’’,None,log) loginlog.save() c# x login c1 P x c2 logout
  • 30. step3. Share message ....... log = getLog(request) def onLog(loginlog): channel.exchange_declare(log.type,‘fanout’) # balabala channel.publish(log.type,’’,None,log) loginlog.save() c# x login c1 P x c2 logout def onLog(logoutlog): # balabala logoutlog.save()
  • 31. Performance test non-persist-mode 100000 msg en-queue de-queue 10,000/s 7,500/s 5,000/s 2,500/s 0/s 128 512 1024 3072 10240
  • 32. Performance tune Parameters for multiple consumer toning: QOS consumer count autoAck?
  • 33. clustering to scale Start rabbit nodes: rabbit1$ rabbitmq-server rabbit2$ rabbitmq-server
  • 34. clustering to scale create cluster: rabbit2$ rabbitmqctl stop_app Stopping node rabbit@rabbit2 ...done. rabbit2$ rabbitmqctl reset Resetting node rabbit@rabbit2 ...done. rabbit2$ rabbitmqctl cluster rabbit@rabbit1 Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done. rabbit2$ rabbitmqctl start_app Starting node rabbit@rabbit2 ...done.
  • 35. clustering to scale Check it out: rabbit1$ rabbitmqctl status Status of node rabbit@rabbit1 ... [..., {nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]}, {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}] ...done.

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n