Mage Titans USA 2016 Magento/Facebook/RabbitMQ

1.298 Aufrufe

Veröffentlicht am

Demonstrate Magento and RabbitMQ integration on example of the Facebook Chat Bot

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Mage Titans USA 2016 Magento/Facebook/RabbitMQ

  1. 1. © 2016 Magento, Inc. Page | 1 Integrations with Magento, end to end story: RabbitMQ, APIs
  2. 2. © 2016 Magento, Inc. Page | 2 Magento 2 Architect: - Magento Service Layer - Composer Integration - Magento CLI - Rabbit MQ Integration @vrann Eugene Tulika
  3. 3. © 2016 Magento, Inc. Page | 3 On average, Magento store integrates with 15 different external systems Integrations Framework: • API In supported by Web API (CE) and RabbitMQ (EE) • API Out supported by RabbitMQ (EE)
  4. 4. © 2016 Magento, Inc. Page | 4 Magento Chat Bot for Facebook Messenger
  5. 5. © 2016 Magento, Inc. Page | 5 Use-Case: Store With Hand-Picked Books • Niche customers with unusual requests
  6. 6. © 2016 Magento, Inc. Page | 6 Use-Case: Store With Hand-Picked Books • Facebook is the best way to reach larger and targeted audience • Facebook Page representing the store • Customers don’t want to leave Facebook to shop in store • Customers ask questions in Messenger
  7. 7. © 2016 Magento, Inc. Page | 7 Facebook Chat Bots API • Manager cannot handle all communications manually • Facebook webhooks for messages received in the chat • Facebook API for responses • Backed by simple AI to understand the context of discussion
  8. 8. © 2016 Magento, Inc. Page | 8 Facebook POSTs message to the Callback Callback.php 200 OK
  9. 9. © 2016 Magento, Inc. Page | 9 Callback POSTs response to Facebook API Callback.php API
  10. 10. © 2016 Magento, Inc. Page | 10 Integration with Magento IN/OUT Using Web API
  11. 11. © 2016 Magento, Inc. Page | 11 Callback makes API request to Magento Messenger Callback.php API Web API Request Magento POSTs response to Facebook
  12. 12. © 2016 Magento, Inc. Page | 12 Web API Service Interface
  13. 13. © 2016 Magento, Inc. Page | 13 Magento API Interfaces • https://github.com/vrann/magebot
  14. 14. © 2016 Magento, Inc. Page | 14 Map Service to the Web API endpoint
  15. 15. © 2016 Magento, Inc. Page | 15 What can go wrong? When customer writes in Messenger: • Blocking request from callback to Magento • Scalability: Magento can be overloaded processing other requests • Availability: Magento API is unreachable at that moment Messages from customer are lost!
  16. 16. © 2016 Magento, Inc. Page | 16 API IN Using RabbitMQ
  17. 17. © 2016 Magento, Inc. Page | 17 • Scripts: https://github.com/vrann/http-rabbitmq-writer Callback puts messages to the Queue Messenger API Callback.php Magento POSTs response to Facebook Rabbit MQ
  18. 18. © 2016 Magento, Inc. Page | 18 Magento: transform Web API to RabbitMQ Map message handler to topic in communication.xml Map consumer to queue in queue_consumer.xml Run consumer(s):
  19. 19. © 2016 Magento, Inc. Page | 19 With Communication & Queue configs We achieved:  Non-Blocking request, response to Facebook sent immediately  Scalability handled by Queue  Availability handled by Queue Communication vs Queue: • Communication Framework is an abstraction around publisher/subscriber. It can be implemented: – with database and HTTP requests instead (webhooks) – in-memory (observers) • Queue is a Transport layer for Communication – configuration of RabbitMQ adapter and topology
  20. 20. © 2016 Magento, Inc. Page | 20 OUT Using RabbitMQ
  21. 21. © 2016 Magento, Inc. Page | 21 • Scripts: https://github.com/vrann/http-rabbitmq-writer Goal: Magento sends messages to Rabbit Messenger API callback.php response.php
  22. 22. © 2016 Magento, Inc. Page | 22 Before: sender interface with the HTTP request
  23. 23. © 2016 Magento, Inc. Page | 23 Now: Sender interface with RabbitMQ Replace preference for MessageSenderInterface in di.xml, Add “Remote” suffix Interface implementation will be auto-generated:
  24. 24. © 2016 Magento, Inc. Page | 24 Publisher & Topology queue_publisher.xml maps generated topic to the exchange queue_topology.xml configures exchange to queue bindings Available from Magento 2.2, before it was in queue.xml
  25. 25. © 2016 Magento, Inc. Page | 25
  26. 26. © 2016 Magento, Inc. Page | 26 Input Messages Handler Input Classifier Search catalog by author Title, image url, description For Input Classifier it is better to use
  27. 27. © 2016 Magento, Inc. Page | 27 Wrap Up • We covered: – Reasons behind Magento Web API data structures – Reasons to use queues – Switch from Web API to the RabbitMQ – Code generation of API OUT for RabbitMQ – Communication framework vs Queue framework – Separation of publishers, consumers, topology in 2.2 – Input Message Handling – Facebook bots! • https://github.com/vrann/facebook-chatbot • https://github.com/vrann/http-rabbitmq-writer • https://github.com/vrann/magebot
  28. 28. © 2016 Magento, Inc. Page | 28 Q&A Write me @vrann (twitter, github)

×