简体   繁体   English

Apache Ignite with Couchbase 作为持久性

[英]Apache Ignite with Couchbase as Persistence

I am trying to use Apache Ignite with Couchbase at the backend as persistence layer.我正在尝试在后端使用Apache Ignite with Couchbase作为持久层。 I am doing this as a data grid so that any changes made to ignite in-memory cache gets written to couchbase eventually.我这样做是作为一个数据网格,以便为点燃内存缓存所做的任何更改最终都会写入 couchbase。 I am implementing this with spring-boot and spring-data. The igniteConfiguration bean looks like this我正在用 spring-boot 和 spring-data 实现这个。igniteConfiguration bean 看起来像这样

@Bean(name = "igniteConfiguration")
    public IgniteConfiguration igniteConfiguration() {
        IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
        CacheConfiguration cache = new CacheConfiguration("sample");
        cache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
        //The below line  where I am confused
        cache.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheStoreImplementationWithCouchbaseRepositoryBean.class);
        cache.setCacheStoreSessionListenerFactories()
        cache.setReadThrough(true);
        cache.setWriteThrough(true);
        
        igniteConfiguration.setCacheConfiguration(cache);

        return igniteConfiguration;
    }

I need to provide one implementation of cacheStore interface of Ignite in order to connect couchbase as backend data store.我需要提供 Ignite 的cacheStore接口的一种实现,以便将 couchbase 连接为后端数据存储。 I configured Couchbase Repository class and created a bean of it in the CacheStoreImplementationWithCouchbaseRepositoryBean.java.我配置了 Couchbase 存储库 class 并在 CacheStoreImplementationWithCouchbaseRepositoryBean.java 中创建了它的一个 bean。 But this repository bean is not getting initiated because CacheStoreImplementation class is not in spring context and getting null always.但是这个存储库 bean 没有被启动,因为 CacheStoreImplementation class 不在 spring 上下文中并且总是得到 null。

As I used spring-data. Now I have正如我使用的 spring-data。现在我有

  1. Spring data repository for Ignite Spring Ignite 数据存储库
  2. Spring data repository for couchbase Spring couchbase 数据存储库
  3. One implementation of cacheStore interface of ignite ignite的cacheStore接口的一种实现

But not sure how to send the couchbase repository bean to the cacheStore implementation in a way so that it uses this repository class to execute crud operation in couchbase internally.但不确定如何以某种方式将 couchbase 存储库 bean 发送到 cacheStore 实现,以便它使用此存储库 class 在 couchbase 内部执行 crud 操作。

bivrantoshakil -比夫兰托沙基尔 -

"I need to provide one implementation of cacheStore interface of Ignite in order to connect couchbase as backend data store. I configured Couchbase Repository class and created a bean of it in the CacheStoreImplementationWithCouchbaseRepositoryBean.java" “我需要提供 Ignite 的 cacheStore 接口的一个实现,以便将 couchbase 连接为后端数据存储。我配置了 Couchbase 存储库 class 并在 CacheStoreImplementationWithCouchbaseRepositoryBean.java 中创建了它的一个 bean”

What documentation/tutorial are you following?您在关注什么文档/教程? Please zip up and post your project and I will investigate.请 zip 发布您的项目,我将进行调查。

I have a few tangential thoughts我有一些切线的想法

  1. you may which to just use Couchbase without Ignite, as the key-value api is really fast, with persistence being asynchronous and configurable.你可以选择不使用 Ignite 的 Couchbase,因为键值 api 非常快,持久性是异步和可配置的。

  2. There is a tutorial of spring data caching with couchbase at https://blog.couchbase.com/couchbase-spring-cache/ You can skip to "Adding Spring Boot Caching Capabilites".https://blog.couchbase.com/couchbase-spring-cache/有一个 spring 数据缓存与 couchbase 的教程,您可以跳至“添加 Z38008DD81C2F4D7985ECF6E0CE8”。

  3. There is tutorial Apache Ignite here - https://www.baeldung.com/apache-ignite-spring-data这里有教程 Apache 点燃 - https://www.baeldung.com/apache-ignite-spring-data

Take a look here to see how store factories are configured: https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store看这里看看 store factory 是如何配置的: https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store

I recommend decoupling your project from CouchBase and/or spring-data to make it simpler, and then adding the appropriate components, one by one, to see where the failure is.我建议将您的项目与 CouchBase 和/或 spring-data 解耦以使其更简单,然后一一添加适当的组件,以查看故障所在。

If you need one bean to be initialized before another bean consider using the appropriate annotations .如果您需要在另一个 bean 之前初始化一个 bean,请考虑使用适当的注释

I found one work around for the issue I was having above.我找到了解决上述问题的方法。 First I created one class to get the Spring Application Context首先我创建了一个 class 来获取 Spring Application Context

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextProvider implements ApplicationContextAware {

private static ApplicationContext context;

/**
 * Returns the Spring managed bean instance of the given class type if it
 * exists. Returns null otherwise.
 * 
 * @param beanClass
 * @return
 */
public static <T extends Object> T getBean(Class<T> beanClass) {
    return context.getBean(beanClass);
}

@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {

    // store ApplicationContext reference to access required beans later on
    ApplicationContextProvider.context = context;
}
}

and then in the CacheStoreImplementationWithCouchbaseRepositoryBean.class I did this -然后在CacheStoreImplementationWithCouchbaseRepositoryBean.class我做了这个 -

//Repository bean
private CouchbaseRepository repository;
@Override
public Employee load(Long key) {
    repository = ApplicationContextProvider.getBean(CouchbaseRepository.class);
    return repository.findById(key).orElse(null);
}

There are examples of using couchbase cache in里面有使用couchbase缓存的例子

git clone git@github.com:spring-projects/spring-data-couchbase.git
cd spring-data-couchbase
./java/org/springframework/data/couchbase/cache/CouchbaseCacheCollectionIntegrationTests.java
./java/org/springframework/data/couchbase/cache/CouchbaseCacheIntegrationTests.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM