Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/valb3r/springbatch-neo4j-adapter
Neo4j persistence layer adapter for Spring Batch. Allows Spring Batch to run directly on the Neo4j database by providing JobRepository persistence adapter.
https://github.com/valb3r/springbatch-neo4j-adapter
java neo4j persistence-layer spring-batch spring-batch-neo4j spring-data-neo4j
Last synced: about 2 months ago
JSON representation
Neo4j persistence layer adapter for Spring Batch. Allows Spring Batch to run directly on the Neo4j database by providing JobRepository persistence adapter.
- Host: GitHub
- URL: https://github.com/valb3r/springbatch-neo4j-adapter
- Owner: valb3r
- License: mit
- Created: 2020-02-02T11:51:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-08T10:34:14.000Z (about 4 years ago)
- Last Synced: 2024-10-10T05:37:36.460Z (2 months ago)
- Topics: java, neo4j, persistence-layer, spring-batch, spring-batch-neo4j, spring-data-neo4j
- Language: Java
- Homepage:
- Size: 226 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Java CI](https://github.com/valb3r/springbatch-neo4j-adapter/workflows/Java%20CI/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/valb3r/springbatch-neo4j-adapter/branch/master/graph/badge.svg)](https://codecov.io/gh/valb3r/springbatch-neo4j-adapter)
[ ![Download](https://api.bintray.com/packages/valb3r/maven/neo4j-adapter/images/download.svg?version=0.1.4) ](https://bintray.com/valb3r/maven/neo4j-adapter/0.1.4/link)# Description
Provides Spring-batch **JobRepository** and related metadata persistence in Neo4J.
# Purpose
Currently, the support of NoSQL databases in Spring-Batch is limited to ItemReader/ItemWriter for Neo4j and Mongo.
This means that to persist state of Spring-Batch job you would need to have an RDMBS database even if you don't need it as there is no `JobRepository` persistence adapter available.
See these open tickets:- https://github.com/spring-projects/spring-batch/issues/877
- https://github.com/spring-projects/spring-batch/issues/1988This project aims to solve this problem for Neo4j. It offers ready to use Spring Batch metadata persistence adapter
for the Neo4j database. This adapter allows Spring Batch to store its metadata directly in Neo4j so that
no RDBMS/SQL database is needed. It is built on top of Spring-Data for entity and repository abstraction and on top of MapStruct to map Spring Batch data structures to Spring-Data Neo4j entities. This way, the amount of boilerplate code to write was kept at the minimum level.# Importing it to your project
## Gradle
```groovy
repositories {
jcenter()
}dependencies {
implementation 'com.github.valb3r.springbatch.adapters:neo4j-adapter:0.1.4'
}
```## Maven
Add `jcenter` repository:
```
false
jcenter
bintray
https://jcenter.bintray.com
```
Import `neo4j-adapter`:
```
com.github.valb3r.springbatch.adapters
neo4j-adapter
0.1.4```
# Artifacts repository:
See `Bintray` repository: [https://bintray.com/valb3r/maven/neo4j-adapter](https://bintray.com/valb3r/maven/neo4j-adapter).
# Spring-Batch DB structure on Neo4j
![DB structure](docs/db_structure.png)
# Examples
All examples can be found inside [examples](examples) folder.
## Configuring
This is the example of how to enable Spring-Batch Neo4j adapter
[Example:Enable Neo4j adapter](examples/src/main/java/com/github/valb3r/springbatch/adapters/examples/neo4j/ExampleApplication.java#L10-L26)
```groovy
@EnableBatchProcessing
@SpringBootApplication(
// Spring-Batch includes this by default, disabling them
exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class
}
)
@EnableSpringBatchNeo4jAdapter
public class ExampleApplication {public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class);
}
}
```After you have enabled Neo4j adapter with `@EnableSpringBatchNeo4jAdapter` you can use Spring-Batch as if it was
RDBMS database. See this snippet for example:[Example:Execute simple batch job](examples/src/main/java/com/github/valb3r/springbatch/adapters/examples/neo4j/SimpleJobService.java#L16-L47)
```groovy
@Slf4j
@Service
@RequiredArgsConstructor
public class SimpleJobService {@Getter
private final AtomicReference result = new AtomicReference<>();private final JobRepository jobRepository;
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;@SneakyThrows
public void runSimpleJob() {
val job = jobBuilderFactory.get("FOO")
.start(stepBuilderFactory.get("ONE").tasklet((a, b) -> {
log.info("STEP ONE!");
return null;
}).build())
.next(stepBuilderFactory.get("TWO").tasklet((a, b) -> {
log.info("STEP TWO!");
result.set("Step TWO DONE");
return null;
}).build())
.build();val exec = jobRepository.createJobExecution("Test one", new JobParameters());
job.execute(exec);
}
}
```## Used by
You can see how to configure the adapter and how to use it in 'real' project here:
- https://github.com/valb3r/time-tracker/ in particular [worker](https://github.com/valb3r/time-tracker/tree/master/worker) submodule.## Connection configuration
The adapter will reuse `spring.data.neo4j` database connection properties if you provide them in
i.e. `application.yml`.
For example:```
spring:
# Run neo4j with docker:
# docker run --rm -d --publish=7474:7474 --publish=7687:7687 --volume=$HOME/neo4j/data:/data -e NEO4J_AUTH=neo4j/docker neo4j/neo4j-experimental:4.0.0-rc01
data:
neo4j:
uri: bolt://localhost:7687
username: neo4j
password: docker
open-in-view: false
use-native-types: true
```All repositories are provided by:
```
@EnableNeo4jRepositories(
basePackages = {
"com.github.valb3r.springbatch.adapters.neo4j.ogm.repository"
}
)
```This way, all of them are configured using the same Spring-Data configuration as you have for your own
Neo4j-repositories.