Services with Echo


I don't find any examples and documentation about the usage of services with the Echo.
Can you describe that?

Hello Alex,

Which "services" are you referring to, exactly? 

How to implement XData Auth demo with Echo enabled?

There is a demo in Echo install (<echo_install_dir>\demos\xdata) that shows how to use Echo with TMS XData. Then if you want to protect the server, just add a JWT middleware to it and only clients sending a valid JWT token will be able to access the server. The process of issuing the token is the same for other servers, and is described here:

Ok, and is it my question: in offline mode will be impossible to work with JWT?

In other words: no offline more if we have JWT middleware?

I don't see the relation between "offline" and "JWT middleware". Two very different things.

Working "offline" means data will be save locally and you can later replicate to a server.
"JWT middleware" is a feature you add to your server to require authentication to its services. If you mean JWT middleware in the server that will receive data for replication, you can use it, when the client that saved data offline wants to send data to the server, it authenticates with the server. It will only need to authenticate when connecting to the server, of course, so there is no relation with "offline"

How to determine, when customer need authenticate on the server?

He will need to authenticate to the server when he needs to connect to the server, i.e., when he needs to send the batches of data to be replicated to the server ("push" data).

Hello again,

Currently I'm have such implementation of Echo server:

  IndyServer: TIndySparkleHTTPServer;
  Echo: TEcho;
  Timer: TSparkleTimer;

procedure ServerStartEcho(const APort: string);
  EchoModule: TEchoServerModule;
  Pool: IDBConnectionPool;
  NodeManager: IEchoNodeManager;
  Conn: IDBConnection;
  Encrypt: IEncryptMiddleware;
  if Assigned(IndyServer) then

  IndyServer := TIndySparkleHTTPServer.Create;

  Pool := TDBConnectionPool.Create(50, TDBConnectionFactory.Create(
    function: IDBConnection
      FDConnection: TFDConnection;
      Connection: TAureliusConnection;
      FDConnection := TFDConnection.Create(nil);
      FDConnection.Params.Values['Database'] := 'C:\Temp\Test.sdb';
      FDConnection.Params.Values['DriverID'] := 'SQLite';
      FDConnection.Params.Values['Encrypt']  := 'enAes_256';
      FDConnection.Params.Values['UserName'] := 'UserName';
      FDConnection.Params.Values['Password'] := 'Password';
      Connection := TAureliusConnection.Create(nil);
      Connection.AdaptedConnection := FDConnection;
      Connection.AdapterName := 'FireDac';
      Connection.SQLDialect := 'SQLite';
      Result := Connection.CreateConnection;
  EchoModule := TEchoServerModule.Create('http://+:' + APort + '/tms/echo', Pool);

  EchoModule.AddMiddleware(TJwtMiddleware.Create('secret', False, True));


  Echo := TEcho.Create(Pool);

  {$IFDEF MSWINDOWS}if not IsDebuggerPresent then{$ENDIF}
    Conn := Echo.Pool.GetConnection;
    TDatabaseManager.Update(Conn, TEcho.Explorer);
    Conn := nil;

  // Get the NodeManager instance
  NodeManager := Echo.GetNodeManager;

  if NodeManager.SelfNode = nil then begin

  Timer := TSparkleTimer.Create(
    procedure(Echo: TObject)
    Echo, 2000, TTimerType.Periodic);

  IndyServer.Active := True;

I can't use this server module for connecting no my services?
Or this is possible?
Can't find any info in documentation

Something like this:

  XClient := TXDataClient.Create;

  XClient.Uri := 'http://localhost:' + APort + '/tms/echo';
  Token := XClient.Service<ILoginService>.Login('testuser', 'testuser');

Or I shoult create another server module with another Uri for this?
And also: my server code is correct and doesn't contain resource leaking?
  1. I suppose you are destroying IndyServer, Echo and Timer at the end of your application?

    2. You are leaking both FDConnection and Connection. Since you are creating it manually, don't use Connection (TAureliusConnection). Just create the FDConnection and return IDBConnection using TFireDacConnectionAdapter using True as the second parameter:

    3. Make sure the timer doesn't perform twice at same time. BatchLoad is not "thread-safe". Set a flag before the processing and reset at the end, and do not execute the timer code if the flag is set.

    4. For extra service operations, use XData a module.