mage titans usa 2016 - eugene tulika - integrations with magento, end to end story: rabbitmq, apis
Post on 08-Jan-2017
54 Views
Preview:
TRANSCRIPT
© 2016 Magento, Inc. Page | 1
Integrations with Magento, end to end story: RabbitMQ, APIs
© 2016 Magento, Inc. Page | 2
Magento 2 Architect:- Magento Service Layer- Composer Integration- Magento CLI- Rabbit MQ Integration
@vrann Eugene Tulika
© 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)
© 2016 Magento, Inc. Page | 4
Magento Chat Bot for Facebook Messenger
© 2016 Magento, Inc. Page | 5
Use-Case: Store With Hand-Picked Books
• Niche customers with unusual requests
© 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
© 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
© 2016 Magento, Inc. Page | 8
Facebook POSTs message to the Callback
Callback.php200 OK
© 2016 Magento, Inc. Page | 9
Callback POSTs response to Facebook API
Callback.php API
© 2016 Magento, Inc. Page | 10
Integration with Magento
IN/OUT Using Web API
© 2016 Magento, Inc. Page | 11
Callback makes API request to Magento
Messenger Callback.php
API
Web API Request
Magento POSTs response to Facebook
© 2016 Magento, Inc. Page | 12
Web API Service Interface
© 2016 Magento, Inc. Page | 13
Magento API Interfaces
• https://github.com/vrann/magebot
© 2016 Magento, Inc. Page | 14
Map Service to the Web API endpoint
© 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!
© 2016 Magento, Inc. Page | 16
API IN Using RabbitMQ
© 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
© 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):
© 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 QueueCommunication 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
© 2016 Magento, Inc. Page | 20
OUT Using RabbitMQ
© 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
© 2016 Magento, Inc. Page | 22
Before: sender interface with the HTTP request
© 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:
© 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
© 2016 Magento, Inc. Page | 25
© 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
© 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
© 2016 Magento, Inc. Page | 28
Q&A
Write me @vrann (twitter, github)
top related