postgresql Hazelcast 4.2中对直写的React式支持

vx6bjr1n  于 2022-12-12  发布在  PostgreSQL
关注(0)|答案(1)|浏览(126)

We wanted to implement WriteThrough/write behind in Hazelcast using MapStore for Postgres DataStore using ReactiveClient. But could not succeed and we are also not getting any sample for reactive approach. We are implementing MapStore Interface to achieve WriteThrough Caching Pattern. we have to inject the Respository in Mapstore and we are trying inject using @Autowired Annotation.
But we are not able to do, we are getting error repository as null.
Can we get some working example for Hazelcast 4.2 with Postgress as Datastore in reactive way? Thanks Jeni Ambrose
We tried with Autowiring the Repositories in Mapstore implementation

erhoui1w

erhoui1w1#

Here's one way:

@Bean
    public Config config(AccountRepository accountRepository) {
        Config config = new ClasspathYamlConfig("hazelcast.yml");

        MapStoreConfig accountMapStoreConfig = new MapStoreConfig();
        accountMapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
        accountMapStoreConfig.setEnabled(true);
        accountMapStoreConfig.setImplementation(new AccountMapLoader(accountRepository));
       
        MapConfig accountMapConfig = new MapConfig();
        accountMapConfig.setName("account");
        accountMapConfig.setMapStoreConfig(accountMapStoreConfig);
        
        config.getMapConfigs().put(accountMapConfig.getName(), accountMapConfig);
 
        return config;
    }

You can have most (or none!) of the config in a static file, load it, and amend it to add Spring managed bits.
Also, 4.2 is old, use 5.2.1 or whatever is newest when you get to doing this.

相关问题