Spring certified China Education Management Center Apache Geode spring data tutorial 16

Posted by Roo on Mon, 03 Jan 2022 13:39:07 +0100

Original title: Spring certified China Education Management Center - spring data tutorial 16 of Apache Geode (spring China Education Management Center)

6.20. 8. Configure logging

To configure or adjust Apache Geode logging, annotate your Spring, Apache Geode client or server application class @ EnableLogging as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableLogging(logLevel="trace")
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

The default log level is "configuration". In addition, this comment does not adjust the log level in the application and applies only to Apache Geode.

See @ EnableLoggingJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= LoggingConfiguration.class)
  @UsesGemFireProperties
 public@interface EnableLogging

The EnableLogging annotation marks a Spring@Configuration Note: Class is used to configure and enable Pivotal GemFire/Apache Geode system logging.

6.20. 9. Configuration statistics

To collect Apache Geode statistics at runtime, annotate your Spring, Apache Geode client or server application class @ EnableStatistics as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableStatistics
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

See @ EnableStatisticsJavadoc.

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = StatisticsConfiguration.class )
  @UsesGemFireProperties 
public @interface EnableStatistics

The EnableStatistics annotation marks a Spring. The @ Configuration annotation Class is used to configure and enable the statistics and runtime indicators of the running pivot gemfire / Apache geode system. take Set statistical sampling enabled to true.

6.20. 10. Configure PDX

To enable Apache Geode PDX serialization, annotate your Spring, Apache Geode client or server application class @ EnablePdx as follows:

@SpringBootApplication
@ClientCacheApplication
@EnablePdx
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

Apache Geode PDX serialization is an alternative to Java serialization with many additional advantages. On the one hand, it makes all your application domain model types serializable without implementing Java io. Serializable.

By default, SDG configures MappingPdxSerializer to serialize your application domain model types, which does not require any special configuration out of the box to correctly identify the application domain objects that need to be serialized, and then perform serialization, because the logical inMappingPdxSerializer is based on the mapping infrastructure of Spring Data.

See @ EnablePdxJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= PdxConfiguration.class)
public@interface EnablePdx

The EnablePdx annotation marks a Spring @ Configuration annotation Class to enable Apache Geode PDX features and functions in the peer-to-peer cache, cluster member or cache client application.

6.20. 11. Configure SSL

To enable Apache Geode SSL, annotate your Spring, Apache Geode client or server application class @ EnableSsl as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableSsl(components = SERVER)
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

At a minimum, Apache Geode requires you to specify keystores and truststores with appropriate configuration properties or attributes. KeyStore and truststore configuration properties or properties may refer to the same KeyStore file. In addition, KeyStore if the file is protected, you will need to specify a user name and password to access the file.

Apache Geode SSL allows you to configure system specific components that require TLS, such as client / server, locator, gateway, and so on. Alternatively, you can use "ALL" to specify that ALL components of Apache Geode use SSL.

See @ EnableSslJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= SslConfiguration.class)
  @UsesGemFireProperties
 public@interface EnableSsl

The enablesssl annotation marks a Spring@Configuration Note: Class is used to configure and enable TCP/IP socket SSL of pivot gemfire / Apache geode.

6.20. 12. Configure security

To enable Apache Geode security, annotate your Spring, Apache Geode client or server application class @ EnableSecurity as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableSecurity
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

On the server, you must configure access to authentication credentials. You can implement the Apache Geode SecurityManager interface or declare one or more Apache Shiro Realms. For more details, see configuring server security.

On the client side, you must configure a user name and password. For more details, see configuring client security.

See @ EnableSecurityJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= { ApacheShiroSecurityConfiguration.class,AutoConfiguredAuthenticationConfiguration.class,GeodeIntegratedSecurityConfiguration.class })
  @UsesGemFireProperties
 public@interface EnableSecurity

The EnableSecurity comment marks a Spring@Configuration Note: Class is used to configure and enable the security features of pivot gemfire / Apache geode for authentication, authorization and post-processing.

6.20. 13. Configuring Apache Geode properties

To configure other low-level Apache Geode properties not covered by the feature oriented SDG configuration annotation, use your Spring, Apache Geode client or server application class @ GemFireProperties, as follows:

@SpringBootApplication
@PeerCacheApplication
@EnableGemFireProperties(
    cacheXmlFile = "/path/to/cache.xml",
    conserveSockets = true,
    groups = "GroupOne",
    remoteLocators = "lunchbox[11235],mailbox[10101],skullbox[12480]"
)
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

Some Apache Geode properties are used only on the client side, while others are used only on the server side. Check the Apache Geode documentation to use each property correctly.

See@ EnableGemFirePropertiesJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= GemFirePropertiesConfiguration.class)
  @UsesGemFireProperties
 public@interface EnableGemFireProperties

The EnableGemFireProperties annotation marks a Spring@Configuration Annotation class for configuring GemFire/Geode system properties at runtime during [Spring Boot] application startup.

6.20. 14. Configure cache

Use Apache's Geode as the cache provider in Spring's cache abstraction, and SDG automatically creates the cache required by Apache's Geode region for your application service components, and then annotate your Spring, Apache's Geode client or server application class @ EnableGemfireCaching and@ EnableCachingDefinedRegions, as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableCachingDefinedRegions
@EnableGemfireCaching
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

Then, continue to define the application services to be cached, as follows:

@Service
public class BookService {

    @Cacheable("Books")
    public Book findBy(ISBN isbn) {
        ...
    }
}

@ EnableCachingDefinedRegions is optional. That is, you can manually define your area as needed.

See@ EnableCachingDefinedRegionsJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @EnableGemfireCaching 
 @Import(value= CachingDefinedRegionsConfiguration.class)
public@interface EnableCachingDefinedRegions

Should The EnableCachingDefinedRegions annotation marks a Spring@Configuration Application annotation class to support Regions spring based cache Abstract annotation applied to the creation of GemFire/Geode of application service methods and types. In addition, this annotation enables spring's cache abstraction EnableGemfireCaching through SDG annotations. It declares spring's EnableCaching annotations and SDG gemfircachemanagerbean definitions.

See@ EnableGemfireCachingJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Inherited 
 @Documented 
 @Import(value= GemfireCachingConfiguration.class)
public@interface EnableGemfireCaching

The EnableGemfireCaching annotation makes Pivotal GemFire or Apache Geode the cache provider in Spring's cache abstraction.

6.20. 15. Configure zones, indexes, repositories, and entities for persistent applications

To simplify creating Spring, Apache Geode persistent client or server applications, use@ Enableentydefinedregions, @ enablegemfirerepositories, and annotate your application class @ EnableIndexing, as follows:

@SpringBootApplication
@ClientCacheApplication
@EnableEntityDefinedRegions(basePackageClasses = Book.class)
@EnableGemfireRepositories(basePackageClasses = BookRepository.class)
@EnableIndexing
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

Use@ The @ EnableIndexing annotation is required for the enableentydefinedregions annotation. For more details, see configuring indexes.

Next, define your entity class and use the @ Region mapping annotation to specify the Region where your entity will be stored. Use the @ Indexed annotation to define the index of the entity field used in the application query, as follows:

package example.app.model;

import ...;

@Region("Books")
public class Book {

  @Id
  private ISBN isbn;

  @Indexed;
  private Author author;

  @Indexed
  private LocalDate published;

  @LuceneIndexed
  private String title;

}

The @ Region("Books") entity class annotation is used to@ Enableentydefinedregions determines the regions required by the application. For more details, see configuring type specific regions and POJO mappings.

Finally, use a simple query to define your CRUD repository to persist and access Books, as follows:

package example.app.repo;

import ...;

public interface BookRepository extends CrudRepository {

  List<Book> findByAuthorOrderByPublishedDesc(Author author);

}

See@ EnableEntityDefinedRegionsJavadoc.

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = IndexConfiguration.class )
public@interface EnableEntityDefinedRegions

Should The enableentydefinedregions annotation marks a Spring@Configuration Application annotation class to support Regions to create GemFire/Geode based on application persistent entities.

See@ EnableGemfireRepositoriesJavadoc.

@target(value= TYPE)
  @Retention(value= RUNTIME)
  @Documented 
 @Inherited 
 @Import(value= GemfireRepositoriesRegistrar.class)
public@interface EnableGemfireRepositories

Enable annotated Repositories for Apache Geode and Spring Data.

See @ EnableIndexingJavadoc.

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface EnableIndexing

The spring @ Configuration annotation marked by the EnableIndexing annotation, the creation Indexes and LuceneIndexes of the Geode enabled by the GemFire / application class are based on the persistent entity field / attribute annotations of the application, such as @ Id, @ Indexed and @ LuceneIndex annotations.

See @ RegionJavadoc.

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface Region

Annotation declares that Region will store the location of the application persistent entity.

See @ IndexedJavadoc.

@Target ( value ={ FIELD , METHOD })
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface Indexed

The Indexed annotation is used for indexing, which creates a GemFire / Geode on GemFire / Geode. GemfirePersistentEntity GemfirePersistentPropertyIndexRegion

See @ LuceneIndexedJavadoc.

@Target ( value ={ FIELD , METHOD })
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface LuceneIndexed

The Lucene indexed annotation is used to index the Geode of GemFire / on the Geode of GemFire / created. GemfirePersistentEntity GemfirePersistentPropertyLuceneIndexRegion