Is there a way to implement schema multi tenancy in dropwizard? The only solution I've found so far is https://github.com/flipkart-incubator/dropwizard-multitenancy but that is using descriminator multi tenancy.
-
if you are using jdbi, this might help. http://manikandan-k.github.io/2015/06/04/Multi_tenant_applications_in_jdbi.html – Manikandan Aug 03 '15 at 03:49
-
I am not unfortunately - I am however working on cloning the dropwizard-hibernate project and implementing similar code to this https://groups.google.com/forum/#!topic/dropwizard-user/vD0FgNVGhEw – Torben Pi Jensen Aug 03 '15 at 16:29
2 Answers
We basically had the same problem. We wanted to support multi-tenancy, but not only on database level. Different customers have certain services configured differently. In order to avoid passing through the tenancyId
everywhere, we came up with a custom scope using Guice. This way, every service that is @TenancyScoped
can get its own predefined configuration or simply the tenancyId
in its constructor. Then your DAOs can use different schemas based on the tenancyId
.
It works quite well for us, even though it might not properly scale if you have too many (maybe > 1000, really depends how complex your configuration is) tenants.
I have posted the details about Guice and custom scopes here: Multi tenancy with Guice Custom Scopes and Jersey.
-
How do you select the schema based on the tenancyId, do I have to do that on all of my queries? – Torben Pi Jensen Oct 04 '15 at 08:53
-
I don't know what you use for your database abstraction. We use mongojack and define the collection/database in the DAOs constructor. This way you don't need to add the `tenanyId` to your queries. I don't know how this can be achieved with e.g. Hibernate. – scho Oct 04 '15 at 08:57
I had the same problem and I created a multitenant hibernate bundle by modifying the current hibernate bundle code. If you still have the requirement you can check it out.
Here is the link: https://github.com/uditnarayan/dropwizard-hibernate-multitenant/

- 109
- 1
- 7