Skip to content

Commit 7596eb2

Browse files
dgafkagitbook-bot
authored andcommitted
GITBOOK-860: No subject
1 parent f50b37d commit 7596eb2

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* [Snapshoting](modelling/event-sourcing/event-sourcing-introduction/event-sourcing-aggregates/snapshoting.md)
5959
* [Working with Metadata](modelling/event-sourcing/event-sourcing-introduction/working-with-metadata.md)
6060
* [Event versioning](modelling/event-sourcing/event-sourcing-introduction/event-versioning.md)
61-
* [Event Stream Persistence](modelling/event-sourcing/event-sourcing-introduction/persistence-strategy/README.md)
61+
* [Event Stream Persistence](modelling/event-sourcing/event-sourcing-introduction/persistence-strategy.md)
6262
* [Persistence Strategies](modelling/event-sourcing/event-sourcing-introduction/persistence-strategy/persistence-strategies.md)
6363
* [Event Serialization and PII Data (GDPR)](modelling/event-sourcing/event-sourcing-introduction/persistence-strategy/event-serialization-and-pii-data-gdpr.md)
6464
* [Projections Introduction](modelling/event-sourcing/setting-up-projections/README.md)

modelling/event-sourcing/event-sourcing-introduction/persistence-strategy/event-serialization-and-pii-data-gdpr.md

+24-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Event Serialization
44

55
Ecotone use [Converters](../../../../messaging/conversion/conversion/) in order to convert Events into serializable form. \
6-
This means we can customize process of serializing and deserializing specific Events and add needed encrypting capabilities. 
6+
This means we can customize process of serializing and deserializing specific Events, to adjust it to our Application.
77

88
So let's assume **UserCreated** Event:
99

@@ -56,10 +56,13 @@ Then the Event Stream would look like above
5656

5757
This basically means we can serialize the Event in the any format we want. 
5858

59-
## Advanced Serialization Support with JMS
59+
{% hint style="success" %}
60+
Having customized Converters for specific Events, is also useful when we need to adjust some legacy Events to new format. We can hook into the deserialization process, and modify the payload to match new structure.
61+
{% endhint %}
6062

61-
When using [JMS Converter](../../../../modules/jms-converter.md) support, we can even customize how we want to serialize given type globally between Messages. This follows on Ecotone's simplicity to ensure we spend as much as possible time on infrastructure part, and move the focus the business side of things. 
63+
## Advanced Serialization Support with JMS
6264

65+
When using [JMS Converter](../../../../modules/jms-converter.md) support, we can even customize how we want to serialize given class, that is used within Events. \
6366
For example we could have User Created Event which make use of `UserName` class.
6467

6568
```php
@@ -102,7 +105,10 @@ Now if we would serialize it without telling JMS, how to handle this class we wo
102105
}
103106
```
104107

105-
Now this is not fully safe, as if we would simply change property name in `UserName.value` to `UserName.name` it would break deserialization of our previous Events. Therefore we want to keep take over the serialization of objects, to ensure stability along the time.
108+
Now this is fine for short-lived applications and testing, however in the long living application this may become a problem. The problem may come from changes, if we would simply change property name in `UserName.value` to `UserName.data` it would break deserialization of our previous Events. \
109+
As `data` does not exists under `name` key.\
110+
\
111+
Therefore we want to keep take over the serialization of objects, to ensure stability along the time.
106112

107113
```php
108114
class UserNameConverter
@@ -135,15 +141,15 @@ With this, with few lines of code we can ensure consistency across different Eve
135141

136142
## PII Data (GDPR)
137143

138-
In case of storing sensitive data, we may be forced by law to ensure that data should be forgotten (e.g. [GDPR](https://gdpr-info.eu/art-17-gdpr/)). This basically that if Customer will ask to delete his data, we will be obligated by law to ensure that this will happen. 
144+
In case of storing sensitive data, we may be forced by law to ensure that data should be forgotten (e.g. [GDPR](https://gdpr-info.eu/art-17-gdpr/)). This basically means, if Customer will ask to us to remove his data, we will be obligated by law to ensure that this will happen. 
139145

140-
However in case of Event Sourced System we rather do not want to delete events, as this is critical operation which is considered dangerous. Deleting Events could affect running Projections, delete too much may raise inconsistencies in the System, and in some cases we may actually want to drop only part of the data - not everything.\
146+
However in case of Event Sourced System we rather do not want to delete events, as this is critical operation which is considered dangerous. Deleting Events could affect running Projections, deleting too much may raise inconsistencies in the System, and in some cases we may actually want to drop only part of the data - not everything.\
141147
Therefore dropping Events from Event Stream is not suitable solution and we need something different. 
142148

143-
Solution that we can use is to change the way we serialize the Event. Like we saw in the previous sections, we can hook into serialization process and set up a way to do so. \
144-
Therefore as Converter as in reality an Service registered in Dependency Container, we may inject anything to them in order to modify the serialization process.
149+
Solution that we can use, is to change the way we serialize the Event. We can hook into serialization process just as we did for normal serialization, and then customize the process.\
150+
Converter in reality is an Service registered in Dependency Container, so we may inject anything we want there in order to modify the serialization process.
145151

146-
So let's assume that we want to encrypt UserCreated Event:
152+
So let's assume that we want to encrypt `UserCreated` Event:
147153

148154
```php
149155
final readonly class UserCreatedConverter
@@ -188,10 +194,9 @@ final readonly class UserCreatedConverter
188194

189195
So what we do here, is we hook into `serialization/deserialization` process and pass the data to `EncryptionService`. As you can see here, we don't store the payload here, we simply store an reference in form o a key.\
190196
\
191-
EncryptionService can as simple as storing this data in the table using key as Primary Key, so we can fetch it easily. It can be stored with plain text or it may be stored with encryption. \
192-
It all depends on our Domain. \
197+
EncryptionService can as simple as storing this data in database table using key as Primary Key, so we can fetch it easily. It can also be stored with encryption in some cryptographic service, yet it may also be stored as plain text. It all depends on our Domain. \
193198
\
194-
However what is important is that we've provided the resource id to the EncryptionService
199+
However what is important is that we've provided the resource id to the `EncryptionService`
195200

196201
```php
197202
$this->encryptingService->encrypt(
@@ -206,15 +211,18 @@ $this->encryptingService->encrypt(
206211
)
207212
```
208213

209-
Now this could be used to delete related Event's data.
214+
Now this could be used to delete related Event's data. \
215+
When Customer comes to us and say, he wants his data deleted, we simply delete by resource:
210216

211217
```php
212218
$this->encryptingService->delete(resource: $userId);
213219
```
214220

215-
That that way this Data won't be available in the System anymore.\
221+
That way this Data won't be available in the System anymore.\
216222
Now we could just allow Converters fails, if those Events are meant to be deserialized, or we could check if given key exists and then return dummy data instead. 
217223

218-
{% hint style="info" %}
219-
If we allow Converters to fail when Serialization happens, we should ensure that related Projections are using simple arrays instead of classes, and handle those cases during Projecting.
224+
{% hint style="success" %}
225+
If we allow Converters to fail when Serialization happens, we should ensure that related Projections are using simple arrays instead of classes, and handle those cases during Projecting.\
226+
\
227+
If we decide to return dummy data, we can keep deserializing those Events for Projections, as they will be able to use them. 
220228
{% endhint %}

modelling/event-sourcing/setting-up-projections/choosing-event-streams-for-projection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Logger
3939

4040
### From Category
4141

42-
In case if using [`Stream Per Aggregate Persistence Strategy`](../event-sourcing-introduction/persistence-strategy/#stream-per-aggregate-strategy) we will need to use categories to target.\
42+
In case if using [`Stream Per Aggregate Persistence Strategy`](../event-sourcing-introduction/persistence-strategy.md#stream-per-aggregate-strategy) we will need to use categories to target.\
4343
If we would listen on `Domain\Ticket` stream using `Stream Per Aggregate` then we would not target any event, as the streams that are created are suffixed by the identifier `Domain\Ticket-123`. 
4444

4545
In that case we can make use of categories in order to target `Domain\Ticket-*.`

0 commit comments

Comments
 (0)