Code Monkey home page Code Monkey logo

Comments (4)

davegarred avatar davegarred commented on June 30, 2024 1

@CumpsD that's correct! I'm leaning on serde to do a lot of the heavy lifting throughout this crate.

from cqrs.

serverlesstechnology avatar serverlesstechnology commented on June 30, 2024

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.

CumpsD avatar CumpsD commented on June 30, 2024

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.

CumpsD avatar CumpsD commented on June 30, 2024

To answer my own question: Seems serde can do this out of the box :)

from cqrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.