CAP icon indicating copy to clipboard operation
CAP copied to clipboard

Support database isolated multi-tenancy

Open mertyildiz41 opened this issue 3 years ago • 10 comments

Hi, When using microservice architecture, event process at the same time with different tenant, may better to archive this information on the header and using multi-tenancy database architecture.

Is it possible to open a new branch for this feature?

mertyildiz41 avatar Oct 28 '20 22:10 mertyildiz41

Hello,

I am not sure what kind of multi-tenant architecture is used in your project. In our practice, the tenant id is stored in the message header, and then the consumer retrieves it from the header.

You can think that message-based and HTTP-based(request-response) have familiar processing methods.

Let me know what you think?

yang-xiaodong avatar Oct 29 '20 01:10 yang-xiaodong

Hello yang-xiaodong,

I sending event for calculation and after whole calculation done i gonna process calculation result, I don't know is it right way but i thinking to follow Received table to event is Success. But multi-tenant is block me is that way. i can't select Received table without tenant id and also hard to where clause inside of content json. Do you have any idea how i know whole events is done after i sending million events. I'll be pleased :)

mertyildiz41 avatar Oct 29 '20 07:10 mertyildiz41

I got it, it seems that querying by tenant-id in json is indeed not a good idea, we will consider support for multi-tenancy.

At present, I think you can create a mapping table, map the Id of the Received table to the tenant Id, and then use the sql join query to get the data you want.

You can get Received table Id using the following code:

[CapSubscribe("xxxxx")]
public void Subscriber2(Person p, [FromCap]CapHeader header)
{
   // received table id
    var id = header[Headers.MessageId]; 
}

yang-xiaodong avatar Oct 29 '20 07:10 yang-xiaodong

Hi @yang-xiaodong , I read the above discussion and it seems that @mertyildiz41 his multi-tenant architecture is based on table or row isolation.
So you plan to add tenantId column in publish and receive table for support multi-tenancy? Do you plan to support a multi-tenant architecture with database isolation? Thanks,

ztzsws1 avatar Nov 17 '20 02:11 ztzsws1

Hello @ztzsws1 ,

The currently architecture unable to support a multi-tenant system with database isolation.

If you have any ideas, please feel free to drop them here

yang-xiaodong avatar Dec 21 '20 10:12 yang-xiaodong

I think it's possible to store the identity of a tenant in Message.Headers and use static fields to allow users to change the identity name of a tenant

colinin avatar Mar 23 '21 00:03 colinin

I think static fields, not the correct way. Bcz with every message delivery with the different tenants. I actually taking tenant info from the user credential. Better to run out from authentication to message header.

mertyildiz41 avatar Mar 24 '21 06:03 mertyildiz41

With our previous messaging solution we attach tennant info to each outgoing message, and then on the reciever side, we have a pipeline before the message end up in the recever function, where we take the tennant info from the message and create a new scope (using (var scope = _serviceProvider.CreateScope()){}) get a scoped tennant info class from the DI container, set tennant info to the class, and then call the reciever function.. Then in the reciever function, and everywhere in the scope of this message we have an injectable tennant info class... Would something like that be possible?

matengo avatar May 07 '21 07:05 matengo

The article "Using CAP library in a multi-tenant application via SubscribeFilter" may give an idea about multitenancy

teomane avatar Dec 08 '21 09:12 teomane