feuc tec 2016 - desacoplando workflows com rabbitmq
TRANSCRIPT
Desacoplamento de Workflows com RabbitMQ
"A única maneira de fazer um excelente trabalho é amar o que você faz." (Steve Jobs)
Bacana!! :)
Clientes MundiPagg - 40% MarketShare
LOJAS DEPARTAMENTO MODA ENTRETENIMENTO ALIMENTOS
Temos mais de 1500 lojas em nosso portfólio, algumas delas são as maiores marcas brasileiras e internacionais.
ÓLEO TV
Vamos dominar o mundo!!
Quer jogar?
Relaxa!! D boa, você vai achar a solução!
{ Seja criativo!! :) =)
Quer um café?
C# .Net
jQuery
PHP
Magento
Angular.js
Node.js
Gulp
Java
Ruby
SQL Server
MongoDB
Kibana
Log StashRedis
RabbitMQCassandra
Scala Akka.Net
Python
TFS
Git
ApacheJira
SentryMonitis
Python
New RelicAzure
Nosso Stack
MVC
REST
Web APIGo
Vamos dominar o mundo!!!!
Faça parte do nosso time!
"A única maneira de fazer um excelente trabalho é amar o que você faz." (Steve Jobs)
Faça parte do nosso time!
{ TEMOS VAGAS }
"A única maneira de fazer um excelente trabalho é amar o que você faz." (Steve Jobs)
Alexandre Brandão
{ Microsoft C# .Net Solution Developer, C++ Linux Developer, C/C++ Embedded Programmer }
<contatos> <twitter>
@abrandaolustosa </twitter> <skype>
[email protected] </skype></contatos>
Gestor de TIAnalista Desenvolvedor Sênior
Arquiteto de Sistemas
curl -data “experiencia=16_anos&motivacao=inovacao%20e%20pesquisa” https://www.mundipagg.com
Message Broker
“Definição” : “An enterprise service bus (ESB) is a software architecture model used for designing and implementing communication between mutually interacting software applications in a service-oriented architecture (SOA)”
{
}
Integraçãode
Sistemas
Recursos
<wrong>Não utilize workflows centralizados e dependentes do banco de dados</wrong>
“Repense sua arquitetura”
Pipeline – Service Bus
{ Soluções – Service Bus }
- RabbitMQ- CloudAMQP (RabbitMQ)- Azure ServiceBus- IBM MQ Series- Amazon SQS- SQL Server Service Broker- Microsoft Message Queue- OpenShift- Kafka
https://www.rabbitmq.com/
• Robust messaging for applications• Easy to use• Runs on all major operating systems• Supports a huge number of developer
platforms• Open source and commercially supported• Multiplatform for Windows, Linux and Mac OS• Erlang
RabbitMQ - SDKs
C# .Net PHP
JavaRuby
ErlangPerl
Javascript
GoPython
Scala
Haskell
The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented middleware. The defining features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security.
AMQP
To become the standard protocol for interoperability between all messaging
middleware
AMQP
PluginsManagement
• Gerenciamento• Configuração• Monitoramento
STOMP/ MQTT• Integrações utilizando outros protocolos de comunicação
Federation / Shovel• Configuração de cluster em redes não confiáveis
Características do RabbitMQ• Queue• Consumer
• Public/Subscriber• Exchange• Channel• Persitent
• Durável / Transiente• Atomicidade• Round-Robin• Acknolodge
• Ack/Nack• TTL (Time to Live)
Tipos de fila do RabbitMQ
• Basic• Work• Topic• Route• Fanout• RPC
Basic - RabbitMQ
P – ProducerC – ConsumerQueue in Red
The simplest thing that does something
Work - RabbitMQ
Distributing tasks among workers
Automatic - Round-Robin
Publish/Subscribe (FanOut)- RabbitMQ
Sending messages to many consumers at once
Exchange Types: direct, topic, headers and fanoutchannel.exchange_declare(exchange='direct_logs', type=‘fanout')
Routing - RabbitMQ
Receiving messages selectivelychannel.exchange_declare(exchange='direct_logs', type='direct')channel.basic_publish(exchange='direct_logs', routing_key=severity, body=message)
Topics - RabbitMQ
Receiving messages based on a patternchannel.exchange_declare(exchange='direct_logs',
type=‘topic')
RPC Async WorkFlow - RabbitMQ
Remote procedure call implementationDefine properties: CorrelationId and ReplyTo (QueueName to reply
message)
Install Client - RabbitMQ{ "require": { "php-amqplib/php-amqplib": "2.5.*" }}
$composer install or update
Tutorial: https://www.rabbitmq.com/tutorials/
API de Autorização { Stack }
Repositório de código: • https://github.com/alexandrebl• https://
github.com/alexandrebl/IMastersPHPExp2016
• NoSQL• Cache de dados• Dicionário (Chave/Valor)• Dados em memória• Persistência como opção• Stand Alone• Cluster• Replicação• Redis-cli• Redis Manager
• NoSQL• Json Format Data• Dados em disco• Stand Alone• Shard• Replica• Mongo Shell• RoboMongo• MongoChef
• PHP Framework• MVC• Open-source• REST API• Event/handle• Console• Composer
Fluxo da API de Autorização
Sending message with PHP
require_once __DIR__ . '/vendor/autoload.php';use PhpAmqpLib\Connection\AMQPStreamConnection;use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPStreamConnection('localhost', 5672, 'guest',
'guest');$channel = $connection->channel();
Sending message with PHP
$channel->queue_declare('hello', false, false, false, false);
$msg = new AMQPMessage('Hello World!');$channel->basic_publish($msg, '', 'hello');
$channel->close();$connection->close();
Receiving message with PHP$callback = function($msg) { echo " [x] Received ", $msg->body, "\n"; };
$channel->basic_consume('hello', '', false, true, false, false, $callback);
while(count($channel->callbacks)) { $channel->wait();}
Sending message with C# .Netusing RabbitMQ.Client;
var factory = new ConnectionFactory() { HostName = "localhost"
};
using(var connection = factory.CreateConnection())using(var channel = connection.CreateModel()){ }
Sending message with C# .Netchannel.QueueDeclare(
queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
Sending message with C# .Netvar body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body);
RabbitMQ - Tutoriaishttps://www.rabbitmq.com/getstarted.html
RabbitMQ – Curso on-linehttps://www.pluralsight.com/courses/rabbitmq-dotnet-developers
RabbitMQ Manager• Free• Gestão de objetos
• Queue• Exchange• Channels• Routing
• Taxa de tranferência• Simulação• Recursos de hardware
Instalação do RabbitMQ Manager
rabbitmq-plugins enable rabbitmq_management
http://server-name:15672/
Azure Service Bus
Azure Service Bus Documentation
Azure Service Bus
•Queue•Notification Services
•Service Bus Pipeline
• IoT Hub Messaging•Dashboard Admin
Microsoft Azure Service Bus Manager
{Seja hoje uma pessoa
melhor do que você foi ontem
}
Pesquise...
Pesquise...Estude...
Pesquise...Estude...
Domine...
Pesquise...Estude...
Influencie...
Domine...
Alexandre Brandão
Twitter: @abrandaolustosaE-mail: [email protected]: +55 (21) 97367-6161
https://github.com/alexandrebl
Obrigado :)
Linkedin: abrandaol
Alexandre Brandão
Twitter: @abrandaolustosaE-mail: [email protected]: +55 (21) 97367-6161
https://github.com/alexandrebl
Perguntas?
Linkedin: abrandaol