0

Can I have two @ClientCacheApplication instances in the same Spring Boot application?

I have two classes: PeopleDataAccess and JobDataAccess. Both of them are a @ClientCacheApplication.

@Service
@ClientCacheApplication(name ="AccessingDataGemFireApplication", logLevel ="error")
@EnableEntityDefinedRegions(basePackageClasses = People.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
@EnableGemfireRepositories(basePackageClasses = PeopleRepository.class)
public class PeopleDataAccess {

  @Autowired
  PeopleRepository peopleRepository;

  public void saveRecord() {
    People alice = new People("Adult Alice", 40);
    People bob = new People("Baby Bob", 1);
    People carol = new People("Teen Carol", 13);
    peopleRepository.save(alice);
    peopleRepository.save(bob);
    peopleRepository.save(carol);
  }
}


@Service
@ClientCacheApplication(name ="AccessingDataGemFireApplication", logLevel ="error")
@EnableEntityDefinedRegions(basePackageClasses = Job.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
@EnableGemfireRepositories(basePackageClasses = JobRepository.class)
public class JobDataAccess {

  @Autowired
  JobRepository jobRepository;

  public void saveRecord() {
    Job firemen = new Job("Firemen");
    Job accounting = new Job("Accounting");
    jobRepository.save(firemen);
    jobRepository.save(accounting);
  }
}
1

Short answer... No. With Pivotal GemFire/Apache Geode, any cache instance (whether a ClientCache or a peer Cache (used server-side)) is a Singleton. That is, there can only be 1 instance per JVM.

Maybe if you describe your UC and what you are trying to accomplish I can provide more direction?

  • I want to create multi module library project with spring boot for gemfire data access. For example , spring boot application A, spring boot application B and spring boot application C calling the same module library. Application A is calling JobDataAccess , application B is calling PeopleDataAccess and application C is calling both JobDataAccess and PeopleDataAccess. Any suggestion how to do it? – Jack Apr 16 at 1:23
  • 1
    Let me rephrase my answer slightly. There are no issues using the @ClientCacheApplication annotation on multiple components in the same (Spring Boot) application. In that case it will simply hand you the existing ClientCache instance created by whatever @ClientCacheApplication annotation component tripped the configuration of a ClientCache instance first. It's just that you should not think you will have multiple ClientCache instances in this case given GemFire/Geode restricts the cache to being a "Singleton". This is of little consequence though... – John Blum Apr 16 at 16:21
  • 1
    By way of example, I wrote a simple test that is not unlike your application configuration arrangement. See here: github.com/jxblum/contacts-application/blob/master/…. It does not use SD Repositories and is not separated into multiple modules, but that is of no matter to illustrate that what you are doing is fine. – John Blum Apr 16 at 16:24
  • 1
    If you are shooting for a bit more isolation between components/modules, then GemFire/Geode additionally offers the concept of Groups. Of course, on the server-side, your corresponding server Regions (People, Job) can be hosted by certain members in the cluster (not all members need to host all Regions). These members can then be placed into Groups. Then, on the client, you can create multiple Pools assigned to a certain Group and then initialize a client Region to a Pool in a particular Group. Of course, there are other arrangements as well. This is just 1 idea. Hope this helps. – John Blum Apr 16 at 16:27
  • Are they any issue in using @EnableGemfireRepositories annotation on multiple component in the same spring boot application? When i run the above the example code above, it always stop immediately after displaying the spring boot logo. When i comment out the @EnableGemfireRepositories(basePackageClasses = JobRepository.class) , it will able to detect the rest of component. – Jack Apr 20 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.