I would like to use AWS Elasticache for Liberty’s session caching, but it looks like Liberty's sessionCache-1.0 feature can only be used with JCache compliant storage. (like Hazelcast, Infinispan, etc...).
so please let me confirm.
Is this correct that it is impossible to use Liberty’s feature (sessionCache-1.0) with AWS Elasticache?
If so, do I need to write custom code for session caching in my application?
If you have any suggestions on how to realize session caching in Liberty, I would appreciate it.
Eventualy I could configure the sessionCache-1.0 feature with redisson.
Followings are the configuration flagment for ElastiCache Redis (Cluster Mode Disabled).
server.xml
・・・
<!-- JCache Library -->
<library id="jCacheVendorLib">
<fileset dir="${shared.resource.dir}/redisson" includes="*.jar"/>
</library>
<!-- Session Replication -->
<httpSessionCache libraryRef="jCacheVendorLib" uri="file:${shared.resource.dir}/redisson/redisson-jcache.yaml"/>
・・・
redisson-jcache.yaml
---
replicatedServersConfig:
idleConnectionTimeout: 10000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
failedSlaveReconnectionInterval: 3000
failedSlaveCheckInterval: 60000
password: null
subscriptionsPerConnection: 5
clientName: xxxxxxx
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
subscriptionConnectionMinimumIdleSize: 1
subscriptionConnectionPoolSize: 50
slaveConnectionMinimumIdleSize: 24
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 24
masterConnectionPoolSize: 64
readMode: "MASTER_SLAVE"
subscriptionMode: "MASTER"
nodeAddresses:
- "redis://xxxxxxxxxxxxxx01.cache.amazonaws.com:6379"
- "redis://xxxxxxxxxxxxxx02.cache.amazonaws.com:6379"
scanInterval: 1000
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.MarshallingCodec> {}
transportMode: "NIO"
Related
I try to deploy a Java EE Application containing several EJB Timer Services (with persistence=true).
The server complains that no datasource was defined:
Caused by: javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalStateException: The ejbPersistentTimer feature is enabled, but the defaultEJBPersistentTimerExecutor persistent executor cannot be resolved. The most likely cause is that the DefaultDataSource datasource has not been configured. Persistent EJB timers require a datasource configuration for persistence.
The ejbPersistentTimer-3.2 feature is turned on.
I can not find an example how to configure such a datasource in the server.xml file
I tried:
<dataSource id="timerDataSource" jndiName="jdbc/timerDataSource">
</dataSource>
<databaseStore id="EJBTimerDatabaseStore"
tablePrefix="EJBTimer_" dataSourceRef="timerDataSource" />
<persistentExecutor
id="defaultEJBPersistentTimerExecutor"
taskStoreRef="EJBTimerDatabaseStore" />
But this seems to be not enoght? Did I need to activate DerbyDB as a feature too?
It looks like your <dataSource> configuration is missing a few items:
A <jdbcDriver> which points to the JDBC driver jar that corresponds with the DB you are using
A <properties> element which identifies DB properties such as the DB server's hostname, port, and DB name.
Since you mentioned using DerbyDB, here is an example of what Derby config might look like:
<dataSource id="timerDataSource" jndiName="jdbc/timerDataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded databaseName="${server.config.dir}/data/EJBTimerDB" createDatabase="create"/>
</dataSource>
<library id="DerbyLib">
<fileset dir="${server.config.dir}/derbyDriverDir/"/>
</library>
For additional info on configuring DataSources in Liberty, check out this doc:
Configuring relational database connectivity in Liberty
I'm trying to figure out the difference between this factories, used in hibernate.cache.region.factory_class property.
Example:
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory" />
<property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate" />
There are 4 possible options.
The 2 options that I know something about is:
org.hibernate.cache.infinispan.InfinispanRegionFactory: for standalone aplications (not in a cluster, I think).
org.hibernate.cache.infinispan.JndiInfinispanRegionFactory: this is bounded to a JNDI in the property hibernate.cache.infinispan.cachemanager.
And I don't have any idea about these 2:
org.jboss.as.jpa.hibernate5.infinispan.SharedInfinispanRegionFactory: ?
org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory: ?
We have a cluster configured on Wildfly 10.1.0 using domain mode. We want to share the entity cache among the nodes and we are having some doubts about how to do that.
If you're using Wildfly, you don't have to worry about setting the region factory class because Wildfly uses Infinispan as second-level cache provider by default. It's all explained here.
All you have to do is enable hibernate.cache.use_second_level_cache and you're good to go. See examples in the docu.
I agree with Galder, +1!
Regarding the purpose of [org.jboss.as.jpa.hibernate5.infinispan.SharedInfinispanRegionFactory][1] + [org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory][2], these classes extend the Hibernate ORM [hibernate-infinispan][3] implementation classes, the purpose being to start the internal WildFly Infinispan cache services used for the JPA second level caching. They also deal with configuration as well. The below links may become outdated over time, as I think we [3] code might move to the Infinispan project (eventually).
A little more of the related code is at [HibernateSecondLevelCache.java][4], which backs up what Galder said. You can see that the WildFly JPA container automatically is setting the region factory class for you (if caching is enabled via [HibernatePersistenceProviderAdaptor.java][5].
I'm not sure if the code links are helpful to you, I thought they might be. :)
As a stackoverflow newbie, I am not allowed to post with more than 2 links, which is why [3] - [5] are invalid links.
Scott
[1] https://github.com/wildfly/wildfly/blob/master/jpa/hibernate5/src/main/java/org/jboss/as/jpa/hibernate5/infinispan/SharedInfinispanRegionFactory.java
[2] https://github.com/wildfly/wildfly/blob/master/jpa/hibernate5/src/main/java/org/jboss/as/jpa/hibernate5/infinispan/InfinispanRegionFactory.java
[3] github.com/hibernate/hibernate-orm/tree/master/hibernate-infinispan
[4] github.com/wildfly/wildfly/blob/master/jpa/hibernate5/src/main/java/org/jboss/as/jpa/hibernate5/HibernateSecondLevelCache.java
[5] github.com/wildfly/wildfly/blob/master/jpa/hibernate5/src/main/java/org/jboss/as/jpa/hibernate5/HibernatePersistenceProviderAdaptor.java#L91
The configuration envolves Infinispan, Hibernate and JGroups.
Using domain-mode on Wildfly10 you'll need this configuration on your application EAR:
<property name="hibernate.cache.use_second_level_cache" value="true"/>
Your server group need to use a profile that has the ha resources(high availability) such as full-ha or ha profiles. These profiles have the Infinispan and JGroups default configuration.
Then, you need to have the private 'Network Interfaces' on ALL Hosts' configuration that share the cache. JGroups uses the private Edit the domain/configuration/host.xml or use the wildfly console admin to add this configuration (200.0.0.171 needs to be replaced by the server's IP):
<interfaces>
...
<interface name="private">
<inet-address value="${jboss.bind.address.private:200.0.0.171}"/>
</interface>
<!-- .... -->
</interfaces>
For example, supposing you have a HostController HC1(with server-1 and server-2) and HC2(with server-3 and server-4)
Starting all the servers and Host Controllers, you'll see on your server.log:
INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-4) ISPN000078: Starting JGroups channel hibernate
....
....
Received new cluster view for channel hibernate: [HC1:server-1, HC2-server-2, HC2-server-3, HC2-server-4]
we are using oracle database, this is how we configured JNDI against oracle on liberty profile, I want to use hikarui-cp instead if javax.sql.ConnectionPoolDataSource.
<library id="oracleJDBCJars" name="oracleJDBCJars">
<fileset dir="${shared.resource.dir}/oracle-jars" includes="*.jar"/>
</library>
<dataSource beginTranForResultSetScrollingAPIs="true"
beginTranForVendorAPIs="false"
commitOrRollbackOnCleanup="rollback"
connectionManagerRef="default-conn-mgr"
isolationLevel="TRANSACTION_READ_COMMITTED"
jndiName="jdbc/dev"
transactional="true"
type="javax.sql.ConnectionPoolDataSource">
<jdbcDriver libraryRef="oracleJDBCJars"/>
<properties.oracle currentSchema="DEV"
databaseName="DBU"
password="Admin12"
portNumber="3714"
serverName="host.local.com"
user="ADMIN"/>
</dataSource>
Opinion part:
First off, I will say that it's probably not necessary to use HikariCP with a Java EE app server. From what I've read, HikariCP is a great connection pool and makes sense to use if you are in a Java SE environment. You might gain a small benefit from using HikariCP in an EE environment, but you will need to jump through additional hoops to get it working when you could just use the Liberty connection pool. In my opinion, your development time will be better spent elsewhere, because Liberty already has a well tested, well performing connection pool out of the box. Using an alternate connection pool on an app server that already provides a good one seems like an unnecessary micro-optimization.
Disclaimer: I am a Liberty developer who works on the connection pool among other things.
To answer your question:
Your configuration is for a DB2 database, not an Oracle database (i.e. properties.oracle should be used instead of properties.db2.jcc). Also, it has many additional properties specified that aren't necessary.
Your configuration can be simplified to this:
<library id="oracleJDBCJars" name="oracleJDBCJars">
<fileset dir="${shared.resource.dir}/oracle-jars" includes="*.jar"/>
</library>
<dataSource jndiName="jdbc/dev">
<jdbcDriver libraryRef="DB2JCC4Jars"/>
<properties.oracle URL="jdbc:oracle:thin:#//host.local.com:3714/DBU"
password="Admin12"
user="ADMIN"/>
</dataSource>
For more info on configuring a data source in Liberty, see this document:
Configuring relational database connectivity in Liberty
Validate your config:
If you have the April beta or newer, you can use the test connection service to check if your data source config works or not. See this article for a walkthrough on how to do that:
Testing database connections in Liberty apps with REST APIs
If you don't have the the April beta or newer, you can write a simple test servlet to attempt to get a connection.
Attempting to use HikariCP:
You will want to modify your jdbc driver <library> to also include the HikariCP jars.
Next, modify your <dataSource> to point to the HikariDataSource implementation. You will need to set 2 attributes (noted below):
<!-- Tell the <dataSource> to use `javax.sql.DataSource` (as opposed to auto-detecting ConnectionPoolDataSource or XADataSource) -->
<dataSource jndiName="jdbc/dev" type="javax.sql.DataSource">
<!-- Tell the <jdbcDriver> what implementation class to use for `javax.sql.DataSource` -->
<jdbcDriver libraryRef="DB2JCC4Jars" javax.sql.DataSource="com.zaxxer.hikari.HikariDataSource"/>
<properties.oracle URL="jdbc:oracle:thin:#//host.local.com:3714/DBU"
password="Admin12"
user="ADMIN"/>
</dataSource>
I am integrating redis with ofbiz by using jedis client.
One redis server is being used by different application.
My question is
How many connection will be hold by JedisPool by default.
If I create multiple JedisPool will it effect redis performance
Note : I am creating JedisPool with default configuration in another application.
client = new JedisPool(ip, port);
Is there any better approach?, suggest me. Thanks
Update : Initiating redis server with default configuratoin user spring data
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${app.cache.redis.host}" p:port="${app.cache.redis.port}" p:password="${app.cache.redis.password}" />
1) How many connection will be hold by JedisPool by default
By using JedisPool with this instantiation,
client = new JedisPool(ip, port);
you are using a GenericObjectPoolConfig from apache-commons-pool.
The default configuration for this generic pool is:
DEFAULT_MAX_TOTAL = 8
DEFAULT_MAX_IDLE = 8
DEFAULT_MIN_IDLE = 0
2) If I create multiple JedisPool will it effect redis performance
Yes and no. If you create multiple JedisPool, you will have more clients connected to Redis. But Redis can support a lot of connected clients with very good performance.
You can set the Redis max client authorized number in redis.conf (for example 10000 clients max).
maxclients 10000
or at startup :
./redis-server --maxclients 10000
or with redis-cli :
127.0.0.1:6379> config set maxclients 10000
In the default configuration, the number of authorized clients is unlimited.
Depending of your use case, you can have multiple JedisPool, or simply increase the size of your JedisPool (to have more than 8 connections).
The iBatis framework has been significantly tweaked between versions 2 & 3, so much that even the config file (now often referred to as MapperConfig.xml) is different.
That being said, there are lots of examples online on how to create a JDBC connection pool with iBatis, but I couldn't find one example on how to do it with JNDI. There is an updated user guide at: http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/trunk/doc/en/iBATIS-3-User-Guide.pdf which does refer to the JNDI settings on page 19, but I still couldn't it get it correctly communicate with the database.
A working example of a JDNI (container managed connection pool) in iBatis 3 would be greatly appreciated!!
Assuming you've already got a JNDI database resource set up, the following environment for iBatis 3's configuration XML file works for me (running on Tomcat):
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">
<property name="data_source" value="java:comp/env/jdbc/webDb"/>
</dataSource>
</environment>
This is what I have in my config file, works well in Glassfish and WebSphere:
<dataSource type="JNDI">
<property name ="data_source" value="jdbc/cpswebmon"/>
</dataSource>
"jdbc/cpswebmon" is the JNDI resource name on my application server