#1 2020-11-24 17:32:49

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

Multi-tenant callbacks

Hello everyone, I would like an opinion from the community. I have the following architecture, a domain layer using interfaces with several hosted tenants using the mormot's ability to define multiple servers in a single connection. This layer is protected. And I have a public layer, also using interfaces, this layer is a client of the domain layer. However, I use a single TSQLHttpServer to communicate with all tenants in the domain layer. For this I use information contained in the jwt token. Well, everything works fine until I now need to work with callbacks. Does anyone have an idea of how to implement this type of architecture?
I cannot implement this in my domain layer because it is protected and not published. However, I need to distinguish between a callback and another in my public layer because it is a client of several mormot servers. I don't know if I explained it well, otherwise I can pass passages of codes to complement the explanation.

Offline

#2 2020-11-24 18:14:29

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

Re: Multi-tenant callbacks

For callbacks, you will use a WebSockets connection.

You should enable the encryption at WebSockets layer.
Then, you authenticate the user as you want (e.g. JWT).
The callbacks will be available only on an already secured WebSockets connection, so no need to add another authentication level.

Offline

#3 2020-11-24 18:39:14

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

Re: Multi-tenant callbacks

Hi ab, I don't know if I expressed myself well, I'll try to describe my architecture:

- (Server 1) I have a TSQLHttpServer that works as a gateway. This is working on port 8888 right.
- (Server 2) this server is a client of domain servers via interface. Then on another server I have the following architecture working on port 8889.:
TSQLHttpServer.Create(GetPort,[FServerTenent1,FServerTenent2,FServerTenent3,
   FServerTenent4]);

So with each request that on server 1 I know which client to instantiate from server 2 because I receive information that distinguishes the servers in the jwt key.
Any and all requests are made by the user on server 1 and not on serverv 2.

Now I'm thinking how to implement a callback server on server 1 and I need to distinguish one client from another on server 2. If I go through a simple array of callbacks, all my connected tenants will receive responses, and this cannot happen. I must propagate messages differentiating one tenant from the other.

I thought about using a record array to control this. Or am I thinking too wrong about it?

Offline

#4 2020-11-24 19:44:02

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

Re: Multi-tenant callbacks

The callbacks are dedicated to each TSQLRestServer instance.

Offline

#5 2020-11-24 19:50:40

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

Re: Multi-tenant callbacks

How can I distinguish the correct callback in this case?
I created something like:

 TCallbackConnection= packed record
    UIDReg:Int64;
    ListCallback:array of IInvokable;
  end; 

Do you think it would work to control callbacks for different tenants?

I pass this UID and the callback instantiates in my subscribe method.

Offline

#6 2020-11-24 20:17:49

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

Re: Multi-tenant callbacks

Why do you need to distinguish each callback?
Each callback will be private to one single TSQLRestServer.

Offline

#7 2020-11-25 12:05:07

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

Re: Multi-tenant callbacks

Hi Ab, it is because my TSQLRestServer works as a gateway. is a TSQLRestServer for several TSQLRestServerDB on another server, and each TSQLRestServerDB is a tenant. I cannot answer calls to all tenants through a callback array. Senao will have a tenant receiving a response from another tenant. And that is not desirable in my architecture.

Offline

#8 2020-11-25 12:42:37

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

Re: Multi-tenant callbacks

Are you confusing TSQLHttpServer and TSQLRestServer kind of classes in your message?

Offline

#9 2020-11-25 13:05:04

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

Re: Multi-tenant callbacks

It is possible to ab. I see that my architecture may have a flaw. Let me see if I can explain it to you. My public server TSQLHttpServer has a TSQLRestServerFullMemory. He is a client of another protected Private server. which has another TSQLHttpServer with several TSQLRestServerDB (each one is a tenant). On this first server I have a route resolver. that connects me as a client on the second server in a desired tenant (TSQLRestServerDB). Confusing this architecture? I understood that callback responds to TSQLRestServer but my architecture is a little different. But I am subject to opinions.

Offline

#10 2020-11-25 13:44:55

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

Re: Multi-tenant callbacks

The callbacks are just interfaces.
If you maintain a list of interfaces in the gateway server, then it could work.
Just as you would do with regular code.

Offline

#11 2020-11-25 14:28:51

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

Re: Multi-tenant callbacks

Ok Ab, thanks for the clarification, I used a record array that contains a list of callbacks and their UIDs. It worked at first I still need to test in thread. Is this architecture that I put in place valid? Sometimes I think I could solve everything with a single server.

Offline

#12 2020-11-25 17:04:46

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

Re: Multi-tenant callbacks

Note that you already have list of callbacks maintained on both server and client sides, e.g. as TSQLRestClientCallbacks on client side.

Offline

#13 2020-11-25 17:44:58

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

Re: Multi-tenant callbacks

Yes Ab, but if I am going to answer every callback that is on the gateway server, it will send responses to tenants who do not expect this answer.

Offline

#14 2020-11-25 19:15:20

mdbs99
Member
From: Rio de Janeiro, Brazil
Registered: 2018-01-20
Posts: 132
Website

Re: Multi-tenant callbacks

@ab
I believe, as he is using a gateway, he don't want the gateway manage these callbacks, only "tenants" know what do do with.

Offline

#15 2020-11-25 19:29:49

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

Re: Multi-tenant callbacks

Oi @ mdbs99, the ideal would be to let the tenants' servers do this management. But callback listeners do not connect directly to these servers, they pass through the gateway. Only he knows which tenant server to request.

Offline

Board footer

Powered by FluxBB