Magento 2 Integrations: ERPs, APIs, Webhooks & Rabbits! - MageTitansUSA 2016

Post on 15-Apr-2017

236 views 0 download

Transcript of Magento 2 Integrations: ERPs, APIs, Webhooks & Rabbits! - MageTitansUSA 2016

@JoshuaSWarren #MageTitansUSA

About Me

• PHP-Based Ecommerce Developer Since 1999

• Magento Developer Since 2008; Magento 2 Developer Since 2014

• Magento Master

• Founder & CEO of Creatuity Corp, Magento Enterprise Solution Partner

@JoshuaSWarren #MageTitansUSA

Integrations

@JoshuaSWarren #MageTitansUSA

Discussing complex, data-intensive integrations

@JoshuaSWarren #MageTitansUSA

Let’s look at the new option in Magento 2

@JoshuaSWarren #MageTitansUSA

What is it? How do we use it?

@JoshuaSWarren #MageTitansUSA

Magento 1 Integration Options

• SOAP API

• REST API*

@JoshuaSWarren #MageTitansUSA

Magento 2 Integration Options

• SOAP API

• REST API

• Web Hooks*

• RabbitMQ*

@JoshuaSWarren #MageTitansUSA

RabbitMQ

@JoshuaSWarren #MageTitansUSA

Messaging Queue

@JoshuaSWarren #MageTitansUSA

Messages can be plaintext, process commands or any other type of

information.

@JoshuaSWarren #MageTitansUSA

Queue is a place where messages are held until a consumer connects and

retrieves them.

@JoshuaSWarren #MageTitansUSA

In other words…

RabbitMQ:These Go to 11

@JoshuaSWarren #MageTitansUSA

RabbitMQ consistently sorts and delivers over one million messages per second

http://bit.ly/2c303Wy

@JoshuaSWarren #MageTitansUSA

Magento hands a message off to RabbitMQ to be handled

asynchronously

@JoshuaSWarren #MageTitansUSA

RabbitMQ can be clustered as you scale up

@JoshuaSWarren #MageTitansUSA

RabbitMQ decouples your Magento code from your integrations using

messages

@JoshuaSWarren #MageTitansUSA

To harness the power of RabbitMQ…

@JoshuaSWarren #MageTitansUSA

think different

@JoshuaSWarren #MageTitansUSA

Bi-directional sync between an ERP/OMS and Magento

Old Way

@JoshuaSWarren #MageTitansUSA

When an order is placed, an event is fired and an observer handles sending

the order data to the ERP

New Way

@JoshuaSWarren #MageTitansUSA

Fire a message to RabbitMQ, move on

@JoshuaSWarren #MageTitansUSA

\Magento\Framework\MessageQueue\PublisherInterface $publisher

$publisher->publish('creatuity.sent.oms', $this->orderInterface);

@JoshuaSWarren #MageTitansUSA

Topics• ‘creatuity.sent.oms’ is the topic

• RabbitMQ can be configured to use topics to route messages to specific queues

• Wildcard routing is possible - i.e., ‘creatuity.*’ would match all topics that start with ‘creatuity.’

• Topics allow the consumers connected to RabbitMQ to easily grab only the messages they need to process

@JoshuaSWarren #MageTitansUSA

Messages

• Can be an object, can be a string - can be anything you’d like

• Allows the application on either end of the integration to use their native format

• Keep it simple

@JoshuaSWarren #MageTitansUSA

Route responses to your Magento code via communication.xml

@JoshuaSWarren #MageTitansUSA

<config xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd"> <topic name="creatuity.sent.oms" request="Magento\Sales\Api\Data\OrderInterface"> <handler name="creatuityoms.sent.oms.handler" type="Creatuity\Oms\Model\Oms" method="saveOmsNum" /> </topic> <topic name="creatuity.sent.magento" request="Magento\Sales\Api\Data\OrderInterface" > <handler name="creatuityoms.sent.magento.handler" type="Creatuity\Oms\Model\Oms" method="saveOmsNum" /> </topic> </config>

@JoshuaSWarren #MageTitansUSA

public function saveOmsNum(\Creatuity\Oms\Model\Oms $oms) { $oms->setData('MagentoOrderNum', $oms->getOrderNum()); $oms->setData('OmsOrderNum', $oms->getOmsNum()); $oms->save(); }

@JoshuaSWarren #MageTitansUSA

Advantages of RabbitMQ

• RabbitMQ can route messages to specific queues for you

• Decouples your code from the API on the other side of the integration

• There is a RabbitMQ client for every major language

• Magento developers write Magento code, ERP developers write ERP code

@JoshuaSWarren #MageTitansUSA

Gotchas

2.0

2.1 2.2

@JoshuaSWarren #MageTitansUSA

Magento 2.0, 2.1 and 2.2 all contain major changes to message queues

@JoshuaSWarren #MageTitansUSA

Magento Enterprise Edition Only

@JoshuaSWarren #MageTitansUSA

One more service to support in your web stack

@JoshuaSWarren #MageTitansUSA

Magento Cloud Edition is a good option to offset this

@JoshuaSWarren #MageTitansUSA

Homework

@JoshuaSWarren #MageTitansUSA

Go try RabbitMQ out

@JoshuaSWarren #MageTitansUSA

The key to success with RabbitMQ & all of Magento 2…

@JoshuaSWarren #MageTitansUSA

Stop trying to apply old patterns and techniques

@JoshuaSWarren #MageTitansUSA

Keep up with the new features and architectural advances

@JoshuaSWarren #MageTitansUSA

RabbitMQ enables us to quickly integrate third-party systems in a new way

@JoshuaSWarren #MageTitansUSA

We still don’t know the upper bound of Magento 2’s scalability

@JoshuaSWarren #MageTitansUSA

Go build something awesome!