Skip to content

Commit df672fc

Browse files
authored
Merge pull request #858 from patchlevel/improve-docs-subscription-worker
Update docs: Gettings started (MesageLoader), Subscription worker usage
2 parents 7f7b817 + 4b45190 commit df672fc

22 files changed

Lines changed: 62 additions & 170 deletions

docs/aggregate-id.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use Patchlevel\EventSourcing\Aggregate\Uuid;
4141
$uuid = Uuid::generate();
4242
$uuid = Uuid::fromString('d6e8d7a0-4b0b-4e6a-8a9a-3a0b2d9d0e4e');
4343
```
44-
4544
:::note
4645
We implemented the version 7 of the uuid, because it is most suitable for event sourcing.
4746
More information about uuid versions can be found [here](https://uuid.ramsey.dev/en/stable/rfc4122.html).
@@ -65,9 +64,8 @@ final class Profile extends BasicAggregateRoot
6564
private CustomId $id;
6665
}
6766
```
68-
6967
:::warning
70-
If you want to use a custom id that is not an uuid,
68+
If you want to use a custom id that is not an uuid,
7169
you need to change the `aggregate_id_type` to `string` in the store configuration.
7270
More information can be found [here](store.md).
7371
:::

docs/aggregate.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ One main difference is that we don't save the current state, but only the indivi
55
This means it is always possible to build the current state again from the events.
66

77
:::note
8-
The term aggregate itself comes from DDD and has nothing to do with event sourcing and can be used independently as a pattern.
8+
The term aggregate itself comes from DDD and has nothing to do with event sourcing and can be used independently as a pattern.
99
You can find out more about Aggregates [here](https://martinfowler.com/bliki/DDD_Aggregate.html).
1010
:::
1111

@@ -44,7 +44,6 @@ final class Profile extends BasicAggregateRoot
4444
}
4545
}
4646
```
47-
4847
:::warning
4948
The aggregate is not yet finished and has only been built to the point that you can instantiate the object.
5049
:::
@@ -77,7 +76,6 @@ final class CreateProfileHandler
7776
}
7877
}
7978
```
80-
8179
:::warning
8280
If you look in the database now, you would see that nothing has been saved.
8381
This is because only events are stored in the database and as long as no events exist,
@@ -109,7 +107,6 @@ final class ProfileRegistered
109107
}
110108
}
111109
```
112-
113110
:::note
114111
You can find out more about events [here](events.md).
115112
:::
@@ -151,7 +148,6 @@ final class Profile extends BasicAggregateRoot
151148
}
152149
}
153150
```
154-
155151
:::tip
156152
Prefixing the apply methods with "apply" improves readability.
157153
:::
@@ -185,7 +181,6 @@ final class NameChanged
185181
}
186182
}
187183
```
188-
189184
:::note
190185
Events should best be written in the past, as they describe a state that has happened.
191186
:::
@@ -262,7 +257,6 @@ final class ChangeNameHandler
262257
}
263258
}
264259
```
265-
266260
:::success
267261
Our aggregate can now be changed and saved.
268262
:::
@@ -309,9 +303,8 @@ final class Profile extends BasicAggregateRoot
309303
}
310304
}
311305
```
312-
313306
:::tip
314-
You don't necessarily need to define multiple `Apply` attributes with the event class
307+
You don't necessarily need to define multiple `Apply` attributes with the event class
315308
if you define the event types in the method using a union type.
316309
:::
317310

@@ -366,7 +359,6 @@ final class Profile extends BasicAggregateRoot
366359
}
367360
}
368361
```
369-
370362
:::warning
371363
When all events are suppressed, debugging becomes more difficult if you forget an apply method.
372364
:::
@@ -399,7 +391,6 @@ final class PersonalInformation extends BasicAggregateRoot
399391
{
400392
}
401393
```
402-
403394
:::warning
404395
You need to define the `SharedApplyContext` attribute on all aggregates that share the apply context.
405396
:::
@@ -443,7 +434,6 @@ final class GuestList extends BasicAggregateRoot
443434
// ...
444435
}
445436
```
446-
447437
:::tip
448438
You can find more about splitting aggregates [here](aggregate.md#splitting-aggregates).
449439
:::
@@ -486,7 +476,6 @@ final class Profile extends BasicAggregateRoot
486476
}
487477
}
488478
```
489-
490479
:::danger
491480
Validations during "apply" should not happen, they will break the rebuilding of the aggregate!
492481
Instead validate the data *before* the event will be recorded.
@@ -573,7 +562,6 @@ final class NameChanged
573562
}
574563
}
575564
```
576-
577565
:::warning
578566
You need to create a normalizer for the `Name` value object.
579567
So the payload must be serializable and unserializable as json.
@@ -793,7 +781,6 @@ final class Shipping extends BasicAggregateRoot
793781
}
794782
}
795783
```
796-
797784
:::tip
798785
With the [SharedApplyContext](aggregate.md#shared-apply-context) attribute,
799786
you can suppress missing applies for events that are handled by other aggregates.
@@ -842,7 +829,6 @@ final class Shipping extends BasicChildAggregate
842829
}
843830
}
844831
```
845-
846832
:::warning
847833
The apply method must be public, otherwise the root aggregate cannot call it.
848834
:::
@@ -890,16 +876,15 @@ final class Order extends BasicAggregateRoot
890876
}
891877
}
892878
```
893-
894879
## Auto Initialize
895880

896881
:::experimental
897882
This feature is still experimental and may change in the future.
898883
Use it with caution.
899884
:::
900885

901-
Sometimes you want to be able to access an aggregate even if it has not yet been created in the system.
902-
In this case, the aggregate should be automatically initialized if it cannot be found in the store.
886+
Sometimes you want to be able to access an aggregate even if it has not yet been created in the system.
887+
In this case, the aggregate should be automatically initialized if it cannot be found in the store.
903888
To achieve this, the aggregate must mark the initialization method with the `AutoInitialize` attribute.
904889
The method must be static, receives the aggregate ID as an argument and must return an instance of the aggregate.
905890

@@ -933,7 +918,6 @@ final class Profile extends BasicAggregateRoot
933918
}
934919
}
935920
```
936-
937921
:::note
938922
Recording events in the `initialize` method is optional but recommended.
939923
:::

docs/cli.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ $cli->addCommands([
141141
new Command\VersionCommand($dependencyFactory, 'event-sourcing:migrations:version'),
142142
]);
143143
```
144-
145144
:::note
146-
Here you can find more information on how to
145+
Here you can find more information on how to
147146
[configure doctrine migration](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.3/reference/custom-configuration.html).
148147
:::
149148

docs/clock.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ $clock = new FrozenClock($firstDate);
6161

6262
$clock->sleep(10); // sleep 10 seconds
6363
```
64-
6564
:::note
6665
The instance of the frozen datetime will be cloned internally, so the it's not the same instance but equals.
6766
:::

docs/command-bus.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ final class CreateProfileHandler
3838
}
3939
}
4040
```
41-
4241
:::note
4342
To use Service Handler you need to register the handler in the `ServiceHandlerProvider`.
4443
:::
@@ -65,7 +64,6 @@ final class CreateProfileHandler
6564
}
6665
}
6766
```
68-
6967
### Union Types
7068

7169
You can also use union types to handle multiple commands and the library will automatically detect the commands.
@@ -82,7 +80,6 @@ final class CreateProfileHandler
8280
}
8381
}
8482
```
85-
8683
### Inheritance
8784

8885
The handler will also be invoked if the command implements an interface or extends a class that the handler expects.
@@ -99,15 +96,14 @@ final class CreateProfileHandler
9996
}
10097
}
10198
```
102-
10399
### Aggregate Handler
104100

105101
Another way to handle commands is to use the aggregates themselves.
106102
To do this, you need to mark the method that handles the command with the `#[Handle]` attribute.
107103

108104
:::note
109-
The aggregates themselves are of course not a service.
110-
The AggregateHandlerProvider uses the aggregates to create the handlers for you.
105+
The aggregates themselves are of course not a service.
106+
The AggregateHandlerProvider uses the aggregates to create the handlers for you.
111107
You can find out more about this in the [providers](command-bus.md#provider) section.
112108
:::
113109

@@ -140,7 +136,6 @@ final class Profile extends BasicAggregateRoot
140136
// ... apply methods
141137
}
142138
```
143-
144139
:::tip
145140
You can find more information about aggregates [here](aggregate.md).
146141
:::
@@ -193,9 +188,8 @@ final class Profile extends BasicAggregateRoot
193188
// ... apply methods
194189
}
195190
```
196-
197191
:::tip
198-
If you want to automatically initialize an aggregate if it cannot be found in the store,
192+
If you want to automatically initialize an aggregate if it cannot be found in the store,
199193
you can use the [Auto Initialize](aggregate.md#auto-initialize) feature.
200194
:::
201195

@@ -233,7 +227,6 @@ final class Profile extends BasicAggregateRoot
233227
// ... apply methods
234228
}
235229
```
236-
237230
:::note
238231
The service must be registered in the service locator.
239232
:::
@@ -274,7 +267,6 @@ final class Profile extends BasicAggregateRoot
274267
// ... apply methods
275268
}
276269
```
277-
278270
:::note
279271
Injection in handler methods is only possible with the `AggregateHandlerProvider`.
280272
:::
@@ -327,7 +319,6 @@ final class CreateProfile
327319
}
328320
}
329321
```
330-
331322
:::tip
332323
You can override the default values for the maximum number of retries and the conditions
333324
by passing them to the `InstantRetry` attribute.
@@ -405,7 +396,6 @@ $provider = new AggregateHandlerProvider(
405396
]), // or other psr-11 compatible container
406397
);
407398
```
408-
409399
:::tip
410400
You can find suitable implementations of psr-11 containers on [packagist](https://packagist.org/search/?tags=PSR-11).
411401
:::

docs/event-bus.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
2020

2121
$eventBus = DefaultEventBus::create([$mailListener]);
2222
```
23-
2423
:::note
2524
The order in which the listeners are executed is determined by the order in which they are passed to the factory.
2625
:::
@@ -56,7 +55,6 @@ $eventBus = new DefaultEventBus(
5655
new DefaultConsumer($listenerProvider),
5756
);
5857
```
59-
6058
:::tip
6159
The `DefaultEventBus::create` method uses the `DefaultConsumer` and `AttributeListenerProvider` by default.
6260
:::
@@ -80,7 +78,6 @@ $listenerProvider = new class implements ListenerProvider {
8078
}
8179
};
8280
```
83-
8481
:::tip
8582
You can use `$listenerDiscriptor->name()` to get the name of the listener.
8683
:::
@@ -103,7 +100,6 @@ final class WelcomeSubscriber
103100
}
104101
}
105102
```
106-
107103
:::tip
108104
If you use psalm, you can use the [event sourcing plugin](https://github.com/patchlevel/event-sourcing-psalm-plugin) for better type support.
109105
:::
@@ -136,7 +132,6 @@ use Patchlevel\EventSourcing\EventBus\Psr14EventBus;
136132

137133
$eventBus = new Psr14EventBus($psr14EventDispatcher);
138134
```
139-
140135
:::warning
141136
You can't use the `Subscribe` attribute with the psr-14 event bus.
142137
:::

docs/events.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ final class ProfileCreated
2727
}
2828
}
2929
```
30-
3130
:::warning
3231
The payload must be serializable and unserializable as json.
3332
:::
@@ -41,7 +40,7 @@ Here are some examples:
4140
* `profile.created`
4241
* `profile.name_changed`
4342
* `hotel.guest_checked_out`
44-
:::
43+
:::
4544

4645
## Alias
4746

@@ -109,14 +108,13 @@ final class ProfileCreated
109108
}
110109
}
111110
```
112-
113111
:::tip
114-
Built-in normalizers like `IdNormalizer` and `DateTimeImmutableNormalizer` can be inferred from the type hint
112+
Built-in normalizers like `IdNormalizer` and `DateTimeImmutableNormalizer` can be inferred from the type hint
115113
and so you don't have to specify them. If you want to configure the Normalizer, you still have to do it.
116114
:::
117115

118116
:::note
119-
You can find out more about normalizer [here](normalizer.md).
117+
You can find out more about normalizer [here](normalizer.md).
120118
:::
121119

122120
## Event Registry

0 commit comments

Comments
 (0)