Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Past Year in Spring for Apache Geode

123 views

Published on

SpringOne 2020
The Past Year in Spring for Apache Geode

John Blum, Staff Engineer at VMware

Published in: Software
  • Be the first to comment

  • Be the first to like this

The Past Year in Spring for Apache Geode

  1. 1. The Past Year in Spring for Apache Geode September 2–3, 2020 springone.io
  2. 2. John Blum Lead… for (P project : Spring for Apache Geode) { manage(project); } @john_blum
  3. 3. … Spring for Apache GeodeAll things… What things?
  4. 4. Spring Boot Spring Data Spring Session Spring Test
  5. 5. Spring Boot Spring Data Spring Session Spring Test
  6. 6. Spring Boot Spring Data Spring Session Spring Test TDP (Test-Driven Presentation)
  7. 7. Spring Test for Apache Geode <STDG/>  Fine-grained control over GemFire/Geode Mock Object Lifecycle [doc]  Mocking Unsupported Cache Operations [doc]  New @EnableGemFireResourceCollector [doc]
  8. 8. GemFire/Geode Mock Object Lifecycle @EnableGemFireMockObjects(destroyOnEvents = { … }) class TestGeodeConfiguration { … } Any event class in package org.springframework.test.context.event  E.g. AfterTestMethodEvent  Defaults to AfterTestClassEvent
  9. 9. EXAMPLE Mocking Unsupported Cache Operations & @EnableGemFireResourceCollector
  10. 10. How To Use Spring Test with Apache Geode  Generate Spring Boot [SBDG] project at start.spring.io  Include spring-geode-starter-test module <dependencies> <dependency> <groupId>org.springframework.geode</groupId> <artifactId>spring-geode-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
  11. 11. Spring Boot Spring Data Spring Session Spring Test
  12. 12. Spring Data for Apache Geode <SDG/>  DATAGEODE-238 – spring-data-gemfire module  DATAGEODE-272 – TransactionListener event publishing  DATAGEODE-152 [Doc]  WIP: DATAGEODE-263 – Paging  WIP: DATAGEODE-262 – Projections  WIP: DATAGEODE-258 – Function Executions on Region from Repository
  13. 13. Manual Transaction Event Publishing @Service class MyTransactionalService { @Autowired ApplicationEventPublisher publisher; @Transactional public void someTransactionalMethod() { try { // do transaction publisher.publish(new CommitEvent()); } catch (DataAccessException e) { publisher.publish(new RollbackEvent(e)); throw e; } } @Component class MyTransactionEventListeners { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void onCommit(CommitEvent event) { // handle commit } @TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK) public void onRollback(RollbackEvent event) { // handle rollback } } https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2 @Configuration @EnableGemfireCacheTransactions class GeodeConfiguration { }
  14. 14. Auto Transaction Event Publishing @Service class MyTransactionalService { @Transactional public void someTransactionalMethod() { // do transaction } } @Component class MyTransactionEventListeners { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void onCommit( TransactionApplicationEvent event) { // handle commit } @TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK) public void onRollback( TransactionApplicationEvent event) { // handle rollback } } https://docs.spring.io/spring-data/geode/docs/current/reference/html/#apis:auto-transaction-event-publishing @Configuration @EnableGemfireCacheTransactions( enableAutoTransactionEventPublishing = true) class GeodeConfiguration { }
  15. 15. Projections, Paging & OnRegion Function Executions interface UserRepository extends CrudRepository<User, String> { // Projection (User -> UserView) UserView findByNameLike(String wildcardName, Sort orderBy); // Paging (Page number, Page size & Sort) List<User> findByNameLike(String wildcardName, Pageable pageRequest); Page<UserView> findByNameLike(String wildcardName, Pageable pageRequest); @Function boolean grant(Set<Long> userIds, Role role); } https://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#repositories.paging-and-sorting @Region(“Users”) class User { @Id Long id; String name; Role role; LocalDateTime lastAccessTime; boolean active; } class UserView { String name; LocalDateTime lastAccessTime; }
  16. 16. OnRegion Function Execution interface UserRepository extends CrudRepository<User, Long> { @Function boolean grant(Set<Long> userIds, Role role); } @OnRegion(region = “Users”) interface UserFunctions { boolean grant(Set<Long> ids, Role role); } ~=
  17. 17. How To Use Spring Data with Apache Geode  Generate Spring Boot [SBDG] project at start.spring.io  spring-geode-starter module (provided) <dependencies> <dependency> <groupId>org.springframework.geode</groupId> <artifactId>spring-geode-starter</artifactId> <scope>test</scope> </dependency> </dependencies>
  18. 18. Spring Boot Spring Data Spring Session Spring Test
  19. 19. Spring Session for Apache Geode <SSDG/>  New Spring Profile to disable OQL Indexes created by SSDG  “disable-spring-session-data-gemfire-indexes”  Principle Name & Session Attributes Indexes  HASH OQL Indexes changed to RANGE/FUNCTION OQL Indexes  Marks identity field (id) of Session object when using PDX Serialization
  20. 20. How To Use Spring Session with Apache Geode  Generate Spring Boot [SBDG] project at start.spring.io  Include spring-geode-starter-session module <dependencies> <dependency> <groupId>org.springframework.geode</groupId> <artifactId>spring-geode-starter-session</artifactId> </dependency> </dependencies>
  21. 21. Spring Boot Spring Data Spring Session Spring Test
  22. 22. Spring Boot for Apache Geode <SBDG/>  Asynchronous (Write-Behind) Inline Caching [doc]  Cache Initialization, i.e. loading Data using JSON [doc]  Support for gemfire.properties in Spring Boot application.properties [doc]
  23. 23. Patterns of Caching  Look-Aside Caching *  Inline Caching  Sync or Async  Near Caching  Multi-Site Caching  Active-Active or Active-Passive
  24. 24. Patterns of Caching  Look-Aside Caching *  Inline Caching  Sync or Async  Near Caching  Multi-Site Caching  Active-Active or Active-Passive Use Cases of Caching  (HTTP) Session Caching  Hibernate L2 Caching  Etc. Inline Caching
  25. 25. Inline Caching CREATE/UPDATE Cache Put Write-Through [sync] Write-Behind [async] READ Cache Get Read-Through [sync] . . . . . . . . . . . .
  26. 26. Inline Caching Write-Through [sync] Write-Behind [async] Read-Through [sync]
  27. 27. Inline Caching CacheWriter CacheLoader Read-Through [sync] Write-Through [sync] Write-Behind [async]
  28. 28. Inline Caching Write-Through [sync] Write-Behind [async] Read-Through [sync] CacheLoaderAsyncEventListener
  29. 29. Inline Caching Applied @Service class UserService { @Cacheable(“UsersByName”) User findBy(String name) { … } }
  30. 30. Synchronous (Read/Write-Through) Inline Caching @Configuration @EnableCachingDefinedRegions class GeodeConfiguration { @Bean InlineCachingRegionConfigurer<User, Long> syncInlineCachingConfigurer( UserRepository userRepository) { return new InlineCachingRegionConfigurer(userRepository, “Users”); } }
  31. 31. Asynchronous (Write-Behind) Inline Caching @Configuration @EnableCachingDefinedRegions class GeodeConfiguration { @Bean AsyncInlineCachingRegionConfigurer<User, Long> asyncInlineCachingConfigurer( UserRepository userRepository) { return AsyncInlineCachingRegionConfigurer.create(userRepository, “Users”) .withQueueBatchConflationEnabled() .withQueueBatchSize(50) .withQueueBatchTimeInterval(Duration.ofSeconds(30)) } } @Bean RepositoryCacheLoaderRegionConfigurer<User, Long> syncInlineCachingConfigurer( UserRepository userRepository) { return new RepositoryCacheLoaderRegionConfigurer(userRepository, “Users”) } } // Write-Behind // Read-Through
  32. 32. gemfire.properties in application.properties # Spring Boot application.properties server.port=8181 spring.application.name=SpringGeodeApplication gemfire.durable-client-id=123 gemfire.enable-time-statistics=${external-enable-stats:true} spring.data.gemfire.cache.client.durable-client-id=987 https://docs.spring.io/spring-boot-data-geode-build/1.4.x/reference/html5/index.html#geode-configuration- gemfire-properties
  33. 33. EXAMPLE Cache Initialization
  34. 34. Spring Boot for Apache Geode <SBDG/>  New Multi-Site Caching Example & Guide [doc / source]  New Security Example & Guide [doc / source]  Auto-configuration for TLS/SSL On-platform [doc]  PCF/PCC  VMware Tanzu GemFire for VMs (BOSH)  New Using Apache Geode with Docker chapter [doc]  New Apache Geode API Extensions chapter [doc]  New spring-geode-starter-logging module [doc]  New spring-geode-bom module [Issue #93]
  35. 35. How To Use Spring Boot with Apache Geode  Generate Spring Boot [SBDG] project at start.spring.io  spring-geode-starter module (provided) <dependencies> <dependency> <groupId>org.springframework.geode</groupId> <artifactId>spring-geode-starter</artifactId> </dependency> </dependencies>
  36. 36. References  Spring Data for Apache Geode (SDG) [ Project | Source | JIRA | PR ]  Spring Test for Apache Geode (STDG) [ | Source | Issues | PR ]  Spring Session for Apache Geode (SSDG) [ Project | Source | Issues | PR ]  Spring Boot for Apache Geode (SBDG) [ | Source | Issues | PR ]  StackOverflow  Examples
  37. 37. Stay Connected. A Deep Dive into Spring Application Events By Oliver Drotbohm Wed, Sept 2 @ 1:05 PM PDT #springone@s1p
  38. 38. Safe Harbor Statement ThefollowingisintendedtooutlinethegeneraldirectionofVMware'sofferings.Itisintendedforinformationpurposesonlyandmay notbeincorporated intoanycontract. Anyinformationregardingpre-releaseofVMwareofferings,futureupdatesorotherplannedmodificationsis subjecttoongoing evaluationbyVMwareandissubjecttochange.Thisinformationisprovidedwithoutwarrantyoranykind, expressorimplied, and isnotacommitmentto deliveranymaterial,code,orfunctionality,and shouldnotberelieduponin makingpurchasingdecisionsregardingVMware's offerings.Thesepurchasing decisionsshould onlybebasedon featurescurrentlyavailable. Thedevelopment,release,and timingofanyfeaturesorfunctionalitydescribedfor VMware'sofferingsin thispresentationremainatthesolediscretionofPivotal. Pivotalhasnoobligationtoupdateforwardlookinginformationin this presentation. 4 2

×