Alexey, Yes we have a multi tenant app,actually not rename the cache ,need to
create a cache for each tenant(employee,manager etc nearly 1000+ entities)
.suppose cache name based on the tenant is *TenantId + "Entities"*.Under
this cache need to store all the entities. Here tenantId is dynamic. Assume
the following is a piece of code
//client c# this one is call frequently to insert the
new entity
IIgnite ignite = Ignition.Start(@"C:\Ignite\ApacheIgnite
2.1 version\apache-ignite-fabric-2.1.0-bin\config\default-config.xml");
//tenant id dynamic
string TenantId = message.TenantId
string cacheName = TenantId + "Entities";
string entityId= message.EntityId;
string EntityData = message.EntityData;
//get or create a cache based on the incoming tenantId
var tenantCache = ignite.GetOrCreateCache<String,
String>(cacheName);
//storing entity into cache as well as db (cache key is
entity Id)
tenantCache[entityId] = new
EntityInfo(TenantId,EntityId, EntityData);
Config file :
-----------
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="tenantId_Entities"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder"
factory-method="factoryOf">
<constructor-arg
value="com.bizruntime.message.MessageCacheStore"/>
</bean>
</property>
</bean>
</list>
</property>
as you told ,created a jar file for java cache store
public class EntityCacheStore extends CacheStoreAdapter<String,Entity>{
public void write(Entry<? extends String, ? extends String> entry)
throws
CacheWriterException {
System.out.println("Hello from ......................");
String key = entry.getKey().toString();
String message = entry.getValue();
try {
String url =
"jdbc:sqlserver://*******:1433;trustServerCertificate=true;encrypt=true;Integrated
Security=SSPI;DatabaseName=TenantName;user=*****;password=*****";
Connection con = DriverManager.getConnection(url);
int updated;
PreparedStatement st = con.prepareStatement("insert
into EmployeeEntity
(tenantId,employeeId,EntityData) values (?, ?, ?)");
st.setString(1,***);
st.setString(2,***);
st.setString(3,***);
updated = st.executeUpdate();
System.out.println("For insert command...............");
// If update failed, try to insert.
} catch (SQLException e) {
throw new CacheWriterException(e.getMessage()+"Failed
to write object
[key=" + key + "+, val=" + message + ']', e);
}
}
and added in the standalone ignite class path, what iam asking is
*//get or create a cache based on the incoming tenantId
var tenantCache = ignite.GetOrCreateCache<String,
String>(cacheName);*,but we have hard coded the cache name in the property
* <property name="name" value="tenantId_Entities"/>*.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/