#1 2017-02-03 19:55:57

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

event sourcing

Hi guys, please forgive me if what I'm posting here is irrelevant.  I've created an educational project "ATM machine simulation" in SmartMobileStudio with withdrawal, deposit, transfer, bill payment, extract, balance options enabled.

See the Live Project at: ATM Machine
If you like to test, use the PIN=1234

I have heard about Event Sourcing before in the forum. I'm wondering based on this example if will give someone   some inspiration to create a demo about this.

I've been considering using Event sourcing in mORMot, but unfortunately, I didn't have a clue how to start, basically,
I know that an "Event" is something that happend in the past; you create an event for every state change of the object, something like:

BankAccountCreated  --> DepositPerformed  --> OwnerChanged  --> WithdrawalPerformed
id: 12                            accountID: 12           accountId: 12         accountId: 12
owner: John                   amount: 20               newOwner: Jane      amount: 10

Using event sourcing, since every change to state is traceable, we can:

- perform mining/analysing financial transactions to track terrorists;
- retroactive event, to make easy to do undo things; track "who did that", "when do that";
- you know which items customers removed from their shopping cart.


Any idea?

Offline

#2 2017-02-05 22:46:39

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: event sourcing

I would like to use a interface-based service "Test" method to send a callback to the server.
I'd like to receive the callback event.

Does anyone can shed some light on this?

type
  IMyCallback = interface(IInvokable)
    ['{5CD49AB1-D5A3-4059-B287-25E939DD2A0B}']
    procedure EventCalledFromServer(const withAValue: integer);
  end;
  IMyService = interface(IInvokable)
    ['{FB31BF33-38C7-45AE-9511-6AC727ADC4F4}']
    procedure MethodWithCallback(const anyParameter: variant; const TheCallBack: IMyCallback);
  end;
type
  TMyServiceClient = class(TInterfacedObject,IMyCallback)
  protected
    fRest: TSQLRestClient;
    // here the callback will point back to "self", so IMyCallback is implemented now
    // but you may set a callback from any another class implementing IMyCallback
    procedure EventCalledFromServer(const withAValue: integer);
  public
    procedure Test;
  end;

procedure TMyServiceClient.Test;
var MyService: IMyService;
begin
  if fRest.Services.Resolve(IMyService,MyService) then
    MyService.MethodWithCallback(1234,self);
end;

procedure TMyServiceClient.EventCalledFromServer(const withAValue: integer);
begin // will be called back by the server
end;

type
  TMyServiceServer = class(TInterfacedObject,IMyService)
  protected
    fCallback: IMyCallback; // for delayed call, in sicClientDriven mode
  public
    procedure MethodWithCallback(const anyParameter: variant; const TheCallBack: IMyCallback);
    procedure AnotherMethod;
  end;

procedure TMyServiceServer.MethodWithCallback(const anyParameter: variant; const TheCallBack: IMyCallback);
begin
  TheCallBack.EventCalledFromServer(1234);
  fCallback := TheCallBack; 
end;

procedure TMyServiceServer.AnotherMethod;
begin
  if assigned(fCallback) then
    fCallBack.EventCalledFromServer(5678);
end;

Offline

#3 2017-02-06 15:49:09

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: event sourcing

Are you using web socket based server or http.sys? AFAIK callbacks are only possible for web socket server.

Offline

#4 2017-02-06 18:07:54

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: event sourcing

No. This pattern (use interface parameters to interface-based service methods to send a callback to the server) can also be via client TSQLRestClient (which may be over HTTP).

{ login }
GET /root/TimeStamp HTTP/1.1
GET /root/Auth?UserName=Supervisor HTTP/1.1
GET /root/Auth?UserName=Supervisor&Password=e20f974a72b2e457d4d1b070ee7a8130e4e34d4fa2bd50422c684f3281917a84&ClientNonce=7218250DB57A2F308A8E4274E0859CB23F8572D76A6244C1B0FA8B28C451F421 HTTP/1.1
GET /root/TimeStamp?session_signature=012B5CCBF1452A52B3B4A862 HTTP/1.1

{ ServiceDefine on the client side }
POST /root/MyOtherService._contract_?session_signature=012B5CCBF1452A53A3E3DCBD HTTP/1.1
[]

POST /root/MyOtherCallback._contract_?session_signature=012B5CCBF1452A53674BAAE9 HTTP/1.1
[]

{ call the Withdrawal client method which will call the server callback MethodWithCallback(amount,self) }
POST /root/MyOtherCallback.Withdrawal?session_signature=012B5CCBF1452A53332FF6F1 HTTP/1.1
[2000]

{ client release }
GET /root/Auth?UserName=Supervisor&Session=19619019&session_signature=012B5CCBF1452A55EEFF2E27 HTTP/1.1

I can't find a way to invoke the Withdrawal method on the ajax client; for initialization of the registered interface, for instance, i believe the resolve method is required on the client side to work.

Offline

Board footer

Powered by FluxBB