An open API service indexing awesome lists of open source software.

https://github.com/anataliocs/stellar-java-rpc

Reference implementation for integrating the Stellar Java SDK [1] with Spring Framework, showcasing how to build efficient, non-blocking RPC calls using CompletableFuture.
https://github.com/anataliocs/stellar-java-rpc

blockchain java spring spring-boot stellar

Last synced: about 1 month ago
JSON representation

Reference implementation for integrating the Stellar Java SDK [1] with Spring Framework, showcasing how to build efficient, non-blocking RPC calls using CompletableFuture.

Awesome Lists containing this project

README

          

# Stellar RPC Service Reference Implementation

This project demonstrates a reference implementation for integrating the Stellar Java
SDK [[1]](https://github.com/stellar/java-stellar-sdk) with Spring Framework, showcasing how to build efficient,
non-blocking RPC calls using CompletableFuture.

## Overview

This implementation provides a clean, asynchronous interface for interacting with the Stellar network, leveraging modern
Java features and Spring Framework capabilities. It demonstrates best practices for building scalable blockchain
applications with Stellar.

### Key Features

- Asynchronous operations using CompletableFuture
- Spring Framework integration
- Clean separation of concerns with interface-based design
- Error handling and logging
- Thread-safe implementation

## Technical Stack

- Java SDK 24
- Spring Framework (Spring MVC)
- Stellar Java SDK 1.0.0
- Lombok for reduced boilerplate
- SLF4J for logging

**Run local server:**

```
./gradlew bootRun
```

### Reference Documentation

For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.com)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.5/gradle-plugin)
* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.5/gradle-plugin/packaging-oci-image.html)
* [GraalVM Native Image Support](https://docs.spring.io/spring-boot/3.4.5/reference/packaging/native-image/introducing-graalvm-native-images.html)
* [Spring Configuration Processor](https://docs.spring.io/spring-boot/3.4.5/specification/configuration-metadata/annotation-processor.html)
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/3.4.5/reference/using/devtools.html)
* [Spring Web](https://docs.spring.io/spring-boot/3.4.5/reference/web/servlet.html)

### Guides

The following guides illustrate how to use some features concretely:

* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)

### Additional Links

These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)
* [Configure AOT settings in Build Plugin](https://docs.spring.io/spring-boot/3.4.5/how-to/aot.html)

## GraalVM Native Support

This project has been configured to let you generate either a lightweight container or a native executable.
It is also possible to run your tests in a native image.

### Lightweight Container with Cloud Native Buildpacks

If you're already familiar with Spring Boot container images support, this is the easiest way to get started.
Docker should be installed and configured on your machine prior to creating the image.

To create the image, run the following goal:

```
$ ./gradlew bootBuildImage
```

Then, you can run the app like any other container:

```
$ docker run --rm -p 8080:8080 stellar-java-rpc:0.0.1-SNAPSHOT
```

### Executable with Native Build Tools

Use this option if you want to explore more options such as running your tests in a native image.
The GraalVM `native-image` compiler should be installed and configured on your machine.

NOTE: GraalVM 22.3+ is required.

To create the executable, run the following goal:

```
$ ./gradlew nativeCompile
```

Then, you can run the app as follows:

```
$ build/native/nativeCompile/stellar-java-rpc
```

You can also run your existing tests suite in a native image.
This is an efficient way to validate the compatibility of your application.

To run your existing tests in a native image, run the following goal:

```
$ ./gradlew nativeTest
```

### Gradle Toolchain support

There are some limitations regarding Native Build Tools and Gradle toolchains.
Native Build Tools disable toolchain support by default.
Effectively, native image compilation is done with the JDK used to execute Gradle.
You can read more
about [toolchain support in the Native Build Tools here](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#configuration-toolchains).

## Best Practices

1. **Error Handling**: Always handle exceptions in async operations
2. **Timeouts**: Configure appropriate timeouts for RPC calls
3. **Logging**: Implement comprehensive logging for debugging and monitoring
4. **Testing**: Write unit tests for all async operations
5. **Resource Management**: Properly manage Server connections

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the LICENSE file for details.