大家好,我目前正在尝试使用Hazelcast作为Spring Batch的持久层,为此我需要创建一个具有Hazelcast支持的DataSource。这样,Spring Batch和Spring Data等项目可以使用Hazelcast + Spring Integration提供的Repository和TransactionManager。
有人知道如何创建指向Hazelcast的DataSource吗?
我试过这样定义一个bean,但没有用,它不起作用:
@Configuration
public class DataSourceConfig {
// @Value("${spring.datasource.url}")
// String url;
// @Value("${spring.datasource.username}")
// String userName;
// @Value("${spring.datasource.password}")
// String pwd;
@SneakyThrows
@Bean
public JobRepository hazelCastJobRepo(DataSource dataSource, HazelcastTransactionManager hazelcastTransactionManager){
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setDataSource(dataSource);
jobRepositoryFactoryBean.setDatabaseType("POSTGRES");
jobRepositoryFactoryBean.setTransactionManager(hazelcastTransactionManager);
return jobRepositoryFactoryBean.getObject();
}
@Bean
public HazelcastInstance hazelcastInstance() {
ClientConfig config = new ClientConfig();
config.setClusterName("dev");
return HazelcastClient.newHazelcastClient(config);
}
@Bean
public HazelcastTransactionManager hazelcastTransactionManager(HazelcastInstance hazelcastInstance) {
return new HazelcastTransactionManager(hazelcastInstance);
}
@Bean
public JobBuilderFactory jobBuilderFactory(JobRepository hazelCastJobRepo){
JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(hazelCastJobRepo);
return jobBuilderFactory;
}
@Bean
public StepBuilderFactory stepBuilderFactory(JobRepository hazelCastJobRepo, HazelcastTransactionManager hazelcastTransactionManager){
StepBuilderFactory stepBuilderFactory = new StepBuilderFactory(hazelCastJobRepo, hazelcastTransactionManager);
return stepBuilderFactory;
}
@Bean
public JobExplorer jobExplorer(){
JobInstanceDao jdbcJobInstanceDao = new JdbcJobInstanceDao();
JobExecutionDao jobExecutionDao = new JdbcJobExecutionDao();
StepExecutionDao stepExecutionDao = new JdbcStepExecutionDao();
ExecutionContextDao executionContextDao = new JdbcExecutionContextDao();
return new SimpleJobExplorer(jdbcJobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
}
@Bean
public ListableJobLocator listableJobLocator(){
return new MapJobRegistry();
}
@Bean
public DataSource dataSource() {
return new DriverDataSource("jdbc:mysql://127.0.0.1:5701", "com.hazelcast.datastore.JdbcDataStoreFactory", new Properties(), "", "");
}
}
1条答案
按热度按时间x4shl7ld1#
参见
com.hazelcast.config.Config
:注册外部数据存储。
看起来你需要这样做:
并将其命名为
getDataStore()
。这是一个新的东西,因为Hazelcast
5.2
,看起来我们真的需要它的喷气流处理器。不知道为什么会处理Hazelcast门面,如果它仍然是一个外部数据库,所以你可以简单地配置常规DataSource
的jdbc:mysql://127.0.0.1:5701
。