Comments (4)
@CumpsD that's correct! I'm leaning on serde to do a lot of the heavy lifting throughout this crate.
from cqrs.
My apologies for the late response. You're quite correct, a new Query
is the correct place to put this.
This might look something like:
struct KafkaEventForwarder {
client: KafkaProducer
}
#[async_trait]
impl Query<BankAccount> for KafkaEventForwarder {
async fn dispatch(&self, aggregate_id: &str, events: &[EventEnvelope<BankAccount>]) {
for event in events {
let payload = serde_json::to_vec(&event.payload).expect("unable to serialized payload");
let record = KafkaRecord::new()
.with_key(aggregate_id)
.with_payload(&payload);
self.client.send(record).await;
}
}
}
from cqrs.
A small follow-up question to this. I adopted this pattern to send the message to SNS, on the receiving end it looks like this:
{
"Type" : "Notification",
"MessageId" : "f5458878-95d1-5aad-82d9-d3d5edf775d9",
"SequenceNumber" : "10000000000000027000",
"TopicArn" : "arn:aws:sns:eu-central-1:xxx:dev-events.fifo",
"Message" : "{\"CustomerDepositedMoney\":{\"amount\":1000.0,\"balance\":9000.0}}",
"Timestamp" : "2022-09-27T22:15:02.834Z",
"UnsubscribeURL" : "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:xxx:dev-events.fifo:aab561d9-73b3-4cdf-b527-9cbfa357eb47"
}
I'm using this as a playground for the events:
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum BankAccountEvent {
AccountOpened {
account_id: String,
},
CustomerDepositedMoney {
amount: f64,
balance: f64,
},
CustomerWithdrewCash {
amount: f64,
balance: f64,
},
CustomerWroteCheck {
check_number: String,
amount: f64,
balance: f64,
},
}
But how do I convert the incoming JSON {"CustomerDepositedMoney":{"amount":1000.0,"balance":9000.0}}
back into an event?
from cqrs.
To answer my own question: Seems serde can do this out of the box :)
from cqrs.
Related Issues (20)
- Questions: deleting events and query by aggregate property HOT 3
- Is there a way to a View that isn't scoped by `aggregate_id`? HOT 1
- Adding Queries and Views after events were emitted. HOT 4
- Use CloudEvents as standard event schema HOT 5
- CQRS no ES HOT 2
- Advised way to extend view retrieval functionality? HOT 3
- Implement `EventStoreDB` as event store provider
- Why are aggregates aware of commands? HOT 1
- load_all / `.iter()` on `ViewRepository` HOT 1
- Add upcaster configuration for event replay HOT 2
- Modifications of Views HOT 2
- Aggregate ID unavailable in command handler HOT 4
- Consistency over mulitple commands HOT 3
- Defining multiple aggregates in `ApplicationState` HOT 1
- `0.4.10` Fails to compile on `1.75` HOT 6
- Allow searching for aggregate instance without aggregate ID HOT 2
- Empty event list being propagated to queries HOT 1
- Implement Nats Jetstream based store HOT 1
- How can I replay all events in the order they were committed? HOT 1
- Control over view_id when creating a view HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqrs.