I am trying to use Hazelcast caching with Spring Boot, having read some documentation I decided to settle for Near Cache configurations, I would like to cache some method calls and use it for Hibernate L2 caching.. the trouble is I haven't exactly seen an example of using Near Cache specifically creating near cache clients and starting the server.
Can I have some code examples for in configuring that setup (nearcache configurations) and how to start the server side.
Configure Hibernate to use Hazelcast client:
<!-- hibernate.cfg.xml -->
<property name="hibernate.cache.hazelcast.use_native_client">true</property>
<property name="hibernate.cache.hazelcast.configuration_file_path">hazelcast-client.xml</property>
and in client config, configure near-cache:
<!-- hazelcast-client.xml -->
<near-cache name="default">
<time-to-live-seconds>90</time-to-live-seconds>
<max-idle-seconds>100</max-idle-seconds>
<in-memory-format>OBJECT</in-memory-format>
</near-cache>
Alternatively, you can set different configurations for each cache region via:
<near-cache name="<entity-cache-region-name>">
These will enable client's near-cahce for Hibernate L2C. You do not need to add any additional config on server side at this point. However, if you also want to configure near-cache for members, you can configure them independently of Hibernate & client side.
Configuration details for both client and member are here in the documentation.
Related
I am trying to setup a spring boot application and looking for options to store the small data in the local cache and then this local cache interacts with Redis server which will be on google cloud platform. This local cache can be shared across multiple nodes. I see Redis pro can help to achieve this but that is not free. Is there any open source option I can use? Or any other way I can set this up in Spring boot? How can I set this local cache which syncs up with the central cache? Any suggestions please?
You can use Redisson https://github.com/redisson/redisson/wiki/14.-Integration-with-frameworks/#1421-spring-cache-local-cache-and-data-partitioning. It's available in the Pro version.
If you would like to implement it by yourself, you would need to implement custom CacheManager that first looks up entries in local cache (implemented likely with something smarter than a HashMap, like Caffeine, if entry not found goes to Redis based CacheManager and then depending on the result puts the data to Caffeine cache.
For storing data in Redis and making sure all nodes are in sync, you can use Redis Pub/Sub mechanism to notify each connected node to update local cache.
Spring Boot for Apache Geode (SBDG) offers client-side caching, or what is commonly referred to as "Near Caching". See here.
HISTORY
Apache Geode is an open source software (OSS), In-Memory Data Grid (IMDG) technology, having an Apache 2 License. Indeed, it can be much more than a cache if need be, but fits perfectly well in the caching use case, at any layer in the application architecture (Web, Service, Data).
The commercial version of Apache Geode is VMware Tanzu GemFire, built on Apache Geode source with support from VMware, if needed. But, to use Apache Geode, is completely free.
In fact, the original Spring Cache Abstraction was inspired by Costin Leau's development (original lead & creator) of Spring Data GemFire, which has been replaced by Spring Data for Apache Geode (SDG), to focus on the OSS offering. (See here/alt-here, then here, as well as from Boot).
SBDG is an extension of SDG to give users of Apache Geode (or alternatively, VMware Tanzu GemFire) a proper and first-class experience using Apache Geode in a Spring context, and specifically with Spring Boot features (e.g. auto-configuration). That is, SBDG is a special extension of Spring Boot catered specifically to Apache Geode to handle a variety of application concerns (like caching) that is owned and maintained by the Spring Team, itself.
SBDG is even capable of handling several caching patterns in addition to "Near Caching". See the topic of caching in general.
Finally, SBDG also includes Spring Session for Apache Geode (SSDG) to handle your Web, HTTP Session state caching concerns independent of you Web container (e.g. Tomcat) using Apache Geode as the caching provider for the HTTP Session state. It is, of course, built on Spring Session core (see here).
I am using spring boot 2.5.3 with Jetty 9.4.43.v20210629. I want to share the session across multiple nodes. In Jetty 9.4 there are lot of changes in session management. I want some reference materials for session replication (using JDBC / File system) with java configurations.
Session replication can be done using spring session with following storage options,
Hazlecast
Database
Redis
MongoDB
spring.session.store-type property should be used to decide the storage type. When multiple nodes / containers point to same storage it will share the session and no need to maintain a sticky session.
Need to add proper dependencies in pom.xml and add annotations when required (ex: #EnableJDBCHttpSession)
sample application yaml changes.
JDBC
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: jdbc
session.jdbc.initialize-schema: always
jpa.database: mysql
jpa.database-platform: org.hibernate.dialect.MySQL5Dialect
datasource.url: jdbc:mysql://mysqldb:3306/user
datasource.username: user
datasource.password: user1234#
datasource.driver-class-name: com.mysql.cj.jdbc.Driver
Redis
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: redis
redis.host: redis
redis.port: 6379
I am trying to access Coherence 12.2.1's cache (deployed in data tier) from application tier (deployed in application tier) that staying same Coherence cluster with different WebLogic clusters.
Oracle stated:
A component-scoped JNDI tree can be used in EJBs, servlets, or JSPs to reference the NamedCache.
To use a component-scoped JNDI lookup, define a resource-ref of type com.tangosol.net.NamedCache in either the web.xml or ejb-jar.xml file. Example 3-2 illustrates a <resource-ref> stanza that identifies myCache as the NamedCache.
in https://docs.oracle.com/cd/E24329_01/web.1211/e24442/coh_wls.htm#COHWL117
I developed a Coherence application and deploy it into local storage enabled WebLogic server (coherence managed server). I used Application Lifecycle Listener to access and initialise cache, it works fine.
I can find the cache was populate up in Coherence cache server by using VisualVM, please see attachment.
But unfortunately, I can't find any thing about the cache in my WebLogic managed server JNDI tree, Please find attachment.
I tried to find out a way to enable Coherence cache server (it was integrated into WebLogic 12c) support JNDI look up.
I found something like this:
<cache-config xmlns:jndi="class://com.oracle.coherence.environment.extensible.namespaces.JNDINamespaceContentHandler">
...
</cache-config>
But unfortunately again, com.oracle.coherence.environment.extensible.namespaces.JNDINamespaceContentHandler was removed from WebLogic 12c. Which means there is no way to enable Coherence data cache JNDI name configuration in Coherence 12cR2.
Any advice please!!
Were you able to create the ConnectionFactory, Outbound pools, etc ?
I suggest you take a look at this post here. It should help you out.
Hope it helps !!
I had configured the Spring-XD, application context.xml to connect to remote gemfire db. I am unable to connect to remote DB. It goes and connect to local gemfire which comes as part of Spring XD installation. Please can anyone assist what must be wrong.
Configuration to disable local gemfire and configure to connect remote :
/spring-xd-1.2.0.RELEASE/xd/config/modules/modules.yml
gemfire:
useLocator: true
host: remote-ip-address
port: 44444
**Configuration to remote connection gemfire - spring-module.xml**
<bean id="template" class="org.springframework.data.gemfire.GemfireTemplate">
<property name="region" ref="restaurants" />
</bean>
<util:properties id="gemfire-props">
<prop key="log-level">warning</prop>
</util:properties>
<gfe:cache properties-ref="gemfire-props" />
<gfe:cache-server bind-address="localhost" port="44444" />
<gfe:replicated-region id="restaurants">
</gfe:replicated-region>
When we deploy custom moudules and run it on spring-xd shell which access and store object in gemfire template it goes and saves it in local gmefire instead of remote gemfire database. Please can anyone guide or suggest right way of confuguring gemfire db.
Regards,
Cleophus P.
XD modules that access Gemfire, e.g., the gemfire source and gemfire sink use client-server configuration.
You have a remote cache server and the module is a client. Connecting via a locator requires all servers and clients in the grid to share the locator addresses. Assuming your Gemfire server installation already has one or more locators running, the module context should contain a client-cache configured with the same locator addresses as the remote cache server. If you are not familiar with Gemfire client-server topology, I suggest you review the product documentation and get a simple stand alone example running against your cache server before attempting to deploy your XD modules.
I know that application servers can typically provide a connection to your database via JNDI. Is it possible for hibernate running in Java SE to provide a JNDI url/datasource like an application container such as Tomcat/Glassfish/Jetty would normally?
From the documentation it seems like it should be possible. You just have to provide a few parameters:
Important Hibernate properties for JNDI datasources
hibernate.connection.datasource (required)
hibernate.jndi.url
hibernate.jndi.class
hibernate.connection.username
hibernate.connection.password