이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 3. Running in Server Mode
Store and retrieve data from remote Data Grid clusters using Hot Rod, a custom TCP binary wire protocol.
3.1. Setting Up the RemoteCacheManager 링크 복사링크가 클립보드에 복사되었습니다!
Provide the location for the Data Grid server so the starter can create the
RemoteCacheManagerbean.The starter first tries to find the server location in
hotrod-client.propertiesand then fromapplication.properties.Use the Spring
@Autowiredannotation to include your own custom cache manager class in your application:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Hot Rod client properties
Specify client configuration in hotrod-client.properties on your classpath, for example:
# List Infinispan or Data Grid servers by IP address or hostname at port 11222. infinispan.client.hotrod.server_list=127.0.0.1:6667
# List Infinispan or Data Grid servers by IP address or hostname at port 11222.
infinispan.client.hotrod.server_list=127.0.0.1:6667
For more information, see org.infinispan.client.hotrod.configuration.
Application properties
Configure your project with application.properties. See Application Properties for more information.
3.2. Configuring Marshalling 링크 복사링크가 클립보드에 복사되었습니다!
Configure Data Grid servers to use Java serialization to marshall objects.
By default Data Grid server uses a ProtoStream serialization library as the default marshaller. However, the ProtoStream marshaller is not supported for Spring integration. For this reason you should use the Java Serialization Marshaller.
Specify the following properties in your
application.properties:infinispan.remote.marshaller=org.infinispan.commons.marshall.JavaSerializationMarshaller infinispan.remote.java-serial-whitelist=your_marshalled_beans_package.*
infinispan.remote.marshaller=org.infinispan.commons.marshall.JavaSerializationMarshaller1 infinispan.remote.java-serial-whitelist=your_marshalled_beans_package.*2 Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3. Cache Manager Configuration Beans 링크 복사링크가 클립보드에 복사되었습니다!
Customize the cache manager with the following configuration beans:
-
InfinispanRemoteConfigurer -
Configuration InfinispanRemoteCacheCustomizerNoteYou can create one
InfinispanRemoteConfigurerbean only. However you can create multiple configurations with the other beans.
InfinispanRemoteConfigurer Bean
Configuration Bean
InfinispanRemoteCacheCustomizer Bean
@Bean
public InfinispanRemoteCacheCustomizer customizer() {
return b -> b.tcpKeepAlive(false);
}
@Bean
public InfinispanRemoteCacheCustomizer customizer() {
return b -> b.tcpKeepAlive(false);
}
Use the @Ordered annotation to apply customizers in a specific order.
3.4. Enabling Spring Cache Support 링크 복사링크가 클립보드에 복사되었습니다!
Add the @EnableCaching annotation to your application to enable Spring Cache support.
When the Data Grid starter detects the RemoteCacheManager bean, it instantiates a new SpringRemoteCacheManager, which provides an implementation of Spring Cache.
3.5. Exposing Data Grid Statistics 링크 복사링크가 클립보드에 복사되었습니다!
Data Grid supports the Spring Boot Actuator to expose cache statistics as metrics.
To use the Actuator, add the following to your pom.xml file:
You must then activate statistics for the appropriate cache instances, either programmatically or declaratively.
Programmatically
Declaratively
<local-cache name="my-cache" statistics="true"/>
<local-cache name="my-cache" statistics="true"/>
The Spring Boot Actuator registry binds cache instances when your application starts. If you create caches dynamically, you should use the CacheMetricsRegistrar bean to bind caches to the Actuator registry, as follows: