![Page 1: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/1.jpg)
Why actor-based systems are the best for microservices
Yaroslav Tkachenko@sap1ens
Director of Engineering, Platform at Bench Accounting
![Page 2: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/2.jpg)
Context
![Page 3: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/3.jpg)
Agenda
• Microservices• Messaging for microservices• EIP and messaging• Actors and messages• All combined… and more
![Page 4: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/4.jpg)
Microservices
![Page 5: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/5.jpg)
Microservices
![Page 6: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/6.jpg)
Microservices
Service A Service B
HTTP API / RPC
“Easy” way
![Page 7: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/7.jpg)
Microservices
Challenges with HTTP API / RPC:• Service discovery• Retries for failures • Routing and load balancing• Webhooks• Tracing• Versions• …
![Page 8: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/8.jpg)
Microservices
But…
![Page 9: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/9.jpg)
Messaging for microservices
![Page 10: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/10.jpg)
Messaging for microservices
We should use only messaging for communication between microservices
![Page 11: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/11.jpg)
Messaging for microservices
Reactive Revealed: Resiliency, Failures vs Errors, Isolation, Delegation and Replication by Jonas Boner
![Page 12: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/12.jpg)
Messaging for microservices
Surviving Micro-services by Richard Rodger
![Page 13: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/13.jpg)
Messaging for microservices
Surviving Micro-services by Richard Rodger
![Page 14: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/14.jpg)
EIP and messaging
![Page 15: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/15.jpg)
EIP and messaging
![Page 16: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/16.jpg)
EIP and messaging
EIP was published in 2003 and it contains 65 patterns
![Page 17: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/17.jpg)
EIP and messagingMessage ChannelMessagePipes and FiltersMessage RouterMessage TranslatorMessage EndpointPoint-to-Point ChannelPublish-Subscribe ChannelDatatype ChannelInvalid Message ChannelDead Letter ChannelGuaranteed DeliveryChannel AdapterMessaging BridgeMessage BusCommand MessageDocument MessageEvent MessageRequest-ReplyReturn AddressCorrelation IdentifierMessage SequenceMessage ExpirationFormat IndicatorIntroduction to Message RoutingContent-Based RouterMessage FilterDynamic RouterRecipient ListSplitterAggregator
ResequencerComposed Message ProcessorScatter-GatherRouting SlipProcess ManagerMessage BrokerEnvelope WrapperContent EnricherContent FilterClaim CheckNormalizerCanonical Data ModelMessaging GatewayMessaging MapperTransactional ClientPolling ConsumerEvent-Driven ConsumerCompeting ConsumersMessage DispatcherSelective ConsumerDurable SubscriberIdempotent ReceiverService ActivatorControl BusDetourWire TapMessage HistoryMessage StoreSmart ProxyTest MessageChannel Purger
![Page 18: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/18.jpg)
Actors and messages
![Page 19: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/19.jpg)
Actors and messages
So, I convinced you that messaging patterns are great. Right?
![Page 20: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/20.jpg)
Actors and messages
But why actors? I can just use a message queue and a bunch of consumers/producers
![Page 21: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/21.jpg)
Actors and messages
Sure! But let’s compare
![Page 22: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/22.jpg)
Actors and messages
ActiveMQ message listener in Java
![Page 23: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/23.jpg)
Actors and messages
ActiveMQ message listener in Java (zoom-in)
public class Server implements MessageListener { // … public void onMessage(Message message) { try { TextMessage response = this.session.createTextMessage(); if (message instanceof TextMessage) { TextMessage txtMsg = (TextMessage) message; String messageText = txtMsg.getText(); response.setText(this.messageProtocol.handleProtocolMessage(messageText)); }
response.setJMSCorrelationID(message.getJMSCorrelationID()); this.replyProducer.send(message.getJMSReplyTo(), response); } catch (JMSException e) { } }
// … }
![Page 24: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/24.jpg)
Actors and messages
Actor-based (Akka) message listener in Scala
class CustomerService extends Actor with ActorLogging with Consumer {
val camel = CamelExtension(system)
camel.context.addComponent("activemq", ActiveMQComponent.activeMQComponent( “tcp://localhost:61616” ))
def endpointUri = "activemq:topic:events"
def receive = { case e: CamelMessage => { sender() ! “SomeMessage” } }}
![Page 25: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/25.jpg)
Actors and messages
Btw, some magic is provided by: Apache Camel
“The most unknown coolest library out there”JM
![Page 26: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/26.jpg)
Actors and messages
Actors give you:
• Simple and high-level abstractions for distribution, concurrency and parallelism• Asynchronous, non-blocking and highly performant message-driven
programming model• Very lightweight event-driven processes (several million actors per GB of heap
memory)
![Page 27: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/27.jpg)
Actors and messages
![Page 28: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/28.jpg)
All combined… and more
![Page 29: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/29.jpg)
All combined… and more
Summary:
• It’s easy to build microservices from scratch using messaging patterns• All these patterns are well-known, tested and documented• Actor model gives very simple abstractions to process and send messages• Bonus: all kinds of routing models, back-pressure, reliable queues, broadcasts
![Page 30: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/30.jpg)
Q&A
![Page 31: Why actor-based systems are the best for microservices](https://reader035.vdocuments.net/reader035/viewer/2022062822/587cef6e1a28ab564b8b5e3f/html5/thumbnails/31.jpg)
Reading list
http://microservices.iohttp://www.enterpriseintegrationpatterns.com/patterns/messaging/https://www.amazon.ca/Reactive-Messaging-Patterns-Actor-Model/dp/0133846830 https://www.youtube.com/watch?v=0pfghZxlFSg https://www.youtube.com/watch?v=JvbUF33sKf8 http://akka.io http://camel.apache.org