Ecotone
Business first

November 2023, 
PHPCon Poland

Agenda

Testing Messaging

Building Blocks

Resilient Messaging

Prepare the exercise
wifi pass: verdevilla

https://github.com/dgafka/
phpcon-2023-ecotone-workshop

Let's discuss Ecotone, but first...

focus on the...

Business

As this is what brings
the value

Common Application challenges to solve:

Integration & Boilerplate code

Resiliency & Recoverability code

Configuration & Bootstrap code 

This is not
Business related code

Business Oriented Architecture

Resilient Messaging

Declarative Configuration

Building Blocks

Business Oriented Code

 Messaging

Object oriented programming, gets people to focus on the lesser idea.
The big idea is Messaging."
~ Alan Kay

Messaging is communication

Message is data record

Command Messages

Event Messages

Sending Messages

Handling Messages

  • Storing Order in database

Placing order flow

  • Sending confirmation e-mail to the customer with the order’s summary
  • Starting delivery process by calling a Shipping Service over HTTP API

Non Message-Driven Architecture

Non-Message Driven Architecture

Resilient Messaging

Message-Driven Architecture

Subscribing to Order Was Placed

"asynchronous_messages"
Queue

Setting up asynchronous channel

RabbitMQ Channel

Amazon SQS Channel

Redis Channel

Database Channel

Symfony Messenger Transport Channel

Data consistency

Outbox Pattern

Keep it within transaction

Handle each message in full isolation

Let it self-heal

Secure the Error Message

Recover Business Flow

bin/console ecotone:deadletter:replay dc4dfdb0-40aa-42f2-930d-8ca13dab3466

Manage Multiple Applications
- Ecotone Pulse

One more important ingredient: Tracing

- Sharing knowledge about high level overview of the system

- Tracing which point of the flow had stopped or failed

- What is the performance at each state of the flow

When failure happens recover fast

Resilient Messaging
Questions and Workshop
(Open in separate IDE)

What happens under the hood?

- Sending and Consumption retries
- Message Isolation
- DLQ and message replays

- Sending and Consuming from RabbitMQ
   - Message Payload Conversion
- Message deduplication

- Connecting Event Handlers
- Queue creation
  - Queue routings 

Integration & Boilerplate code

Resiliency & recoverability code

Configuration & Bootstrap code 

Building Blocks

Prepare the exercise

Building Blocks in Ecotone

Command/Event/Query Handlers

Aggregates / Sagas

Event Sourcing Projections

Much of technical code

Orchestration

Introduce Aggregate

Repository

API stays the same

Actions on Aggregate

Routing based Actions

Aggregates subscribing to Events

Orchestration

Get rid of orchestration

Routing based Events

Avoiding Manual Transformations

With bad architecture,
don't expect Domain focus

With good architecture,
Domain comes forward naturally

Building Blocks
Questions and Workshop
(Open in separate IDE)

What we achieved?

- Is done by used messaging

- Aggregates can be connect
to Messaging directly in a POPO way

Integration & Boilerplate code

Resiliency & recoverability code

Configuration & Bootstrap code 

- Application/Service layer can be removed

- Events can be recorded in Aggregate

- Building Blocks can be connected seamlessly

Testing
Messaging

Prepare the exercise

Rules of maintainable tests

Isolate tested flow

Keep tests close to production
like run

Test business use case

1. Isolate tested flows

Bootstrap Ecotone Lite

Executing Test Scenario

2. Test business use case

All starts at API level

- Aggregates are our API

- Messages are our API

Testing Messaging Aggregates

Testing Aggregate API

3. Keep tests close to production run

Synchronous Actions

Asynchronous Actions

More Production like using real Async

Sending and Consuming from Message Channel (Queue)

Message Serialization and Deserialization

Integration with Message Broker

Full Asynchronous Test

Higher Level Abstraction Testing

Testing Messaging
Questions and Workshop

What we achieved?

- Is done and tested in Messaging

- Bootstraping and configuration happens in Ecotone Lite

Integration & Boilerplate code

Resiliency & recoverability code

Configuration & Bootstrap code 

- Integration is production like done by Ecotone

- We reduce boilerplate to minimum as Ecotone provides sensible defaults

Thank you

Tips, Tricks and Features

Start small with your current code base

Integrates with Symfony and Laravel

Can be used stand-alone or with any other framework with Ecotone Lite

Can be introduced for
single feature first

Message Headers (Metadata)

Message Consumer Deduplication

Consume Message
from Message Broker

Handle Message

Acknowledge Message
in Message Broker

Consume Message
from Message Broker

Acknowledge Message
in Message Broker

Message Handler Deduplication

Interceptors

Interceptors Pointcuts

Custom Attribute Pointcut

Interceptor Types

Presend

Before

Around

After

Schedulers

Doctrine ORM Repository

Inbuilt Repositories

Eloquent Repository 

Prooph Event Sourcing Repository 

Document Store Repository 

Storing Aggregates

Projections

Questions?

Ecotone and Message-Driven Architcture - Nov 2023 PHPCon

By Dariusz Gafka

Ecotone and Message-Driven Architcture - Nov 2023 PHPCon

  • 194