#1 2020-12-19 00:09:07

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

SOA - reconnect

I'm checking for connection to rest server using ServerTimestampSynchronize as documented:

    /// you can call this method to call the remote URI root/Timestamp
    // - this can be an handy way of testing the connection, since this method
    // is always available, even without authentication
    // - returns TRUE if the client time correction has been retrieved
    // - returns FALSE on any connection error - check LastErrorMessage and
    // LastErrorException to find out the exact connection error
    function ServerTimestampSynchronize: boolean;

so how can I reconnect to the rest when I get an error calling ServerTimestampSynchronize method. I can't find the Close method in TSQLRestClientURI.

connector := TSQLHttpClientWebsockets.Create(AnsiString(host), AnsiString(port), serverAccess, ssl, '', '', 5000, 5000, 10000);

Offline

#2 2020-12-19 09:19:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,205
Website

Re: SOA - reconnect

What "Close" method are your expecting to find?

There is no such method: the connection is recreated the next time you try to connect.

Offline

#3 2020-12-19 16:29:17

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Re: SOA - reconnect

Using the Demos\ThirdParty\Goerge demo.

1. I'm starting the server Websocket/Json
2. Starting client
3. Clicked the SUM method - response is ok
4. Closed the server
5. Started server
6. Clicked the SUM method - an error occured:


---------------------------
Debugger Exception Notification
---------------------------
Project mORMotRESTcl.exe raised exception class EInterfaceFactoryException with message 'TInterfacedObjectFakeClient.FakeCall(IRestMethods.Sum) failed: 'URI service/RestMethods.Sum [80.6,12.3] returned status 'Not Found' (404 - Network problem or request timeout)''.
---------------------------
Break   Continue   Help   
---------------------------

So I thought that I have to close the REST client connection after I get that error. What's the other solution? Free the client and recreate an object again?

Offline

#4 2020-12-20 21:02:17

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: SOA - reconnect

You have to handle network errors, in that 3rd party example you're using interface based services so if you restart the server like that it's best to re-create the client.

Offline

#5 2020-12-20 21:15:26

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Re: SOA - reconnect

I thought so.

I've implemented it like that:

fClient.OnFailed := Err;

procedure tRestClient.Err(Sender: TSQLRestClientURI; E: Exception;
  Call: PSQLRestURIParams);
begin
  if not StatusCodeIsSuccess(Call.OutStatus) then
    postmessage(Form1.Handle, WM_FAIL, 0, 0);
end;

procedure TForm1.RestartClient(var message: TMessage); message WM_FAIL;
begin
   StartStopClient(Restart);
end;

that's correct procedure?

Last edited by radexpol (2020-12-20 21:20:41)

Offline

#6 2020-12-20 21:27:22

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: SOA - reconnect

yes that should work (for that specific example), Err event could be called several times so you should make sure the postmessage is sent only once when needed.

Last edited by pvn0 (2020-12-20 21:30:43)

Offline

#7 2021-08-03 16:20:43

fabiovip2019
Member
Registered: 2019-03-14
Posts: 76

Re: SOA - reconnect

Hi @radexpol

I implemented this event to handle ORM reconnections in my project. It is called when a request occurs and returns an error, it worked ok, however this request which triggered the error event, it is not executed. You know how to fire a request of your own that fired the error event?

I don't know if I was too confused eheheh

Offline

Board footer

Powered by FluxBB