6. Facebook Page
• 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. Facebook Chat Bots
• When store Manager cannot handle all communications manually
• Facebook webhooks for messages received in the chat
• Facebook API for responses
16. On average, Magento store has integrations
with 15 different external systems
Integrations Framework:
• API In supported by Web API (CE) and RabbitMQ (EE)
• API Out supported by RabbitMQ (EE)
17. Callback Makes API Request to Magento
Messenger Callback.php
API
Web API Request
Magento POSTs response to Facebook
21. 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 can be lost!
23. Callback Puts Messages to the Queue
• Scripts: https://github.com/vrann/http-rabbitmq-writer
Messenger
API
Callback.php
Magento POSTs response to Facebook
Rabbit MQ
24. Transformation of Web API to Inbound Calls via RabbitMQ
Map message handler to topic in communication.xml
Map consumer to queue in queue_consumer.xml
Run consumer(s):
25. Communication & Queue Configurations
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
29. Now: Sender Interface Using RabbitMQ
Replace preference for MessageSenderInterface in di.xml,
Add “Remote” suffix
Interface implementation will be auto-generated:
30. Publisher & Topology
queue_publisher.xml maps generated topic to the exchange
queue_topology.xml configures exchange to queue bindings
• Prior to Magento EE 2.2 these config are in queue.xml
31. 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