Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleshjdev/vertx-aerospike-client
Vertx Aerospike Client
https://github.com/sleshjdev/vertx-aerospike-client
aerospike async java reactor vertx
Last synced: 20 days ago
JSON representation
Vertx Aerospike Client
- Host: GitHub
- URL: https://github.com/sleshjdev/vertx-aerospike-client
- Owner: sleshJdev
- License: mit
- Created: 2022-10-17T22:33:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-22T19:14:54.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T02:23:37.676Z (2 months ago)
- Topics: aerospike, async, java, reactor, vertx
- Language: Java
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Vertx Aerospike Client
* Provides future based implementation of async aerospike client (AsyncAerospikeClient -> VertxAerospikeClient)
* Extends the aerospike's event loops to be aware about vert'x context event loop and use whenever it's possible### Installation
#### Maven
```xml
dev.slesh
vertx-aerospike-client
1.0.0
io.vertx
vertx-core
4.3.8
com.aerospike
aerospike-client
6.0.0
```
#### Gradle
```kotlin
repositories {
mavenCentral()
}implementation("dev.slesh:vertx-aerospike-client:1.0.0")
implementation("io.vertx:vertx-core:4.3.8")
implementation("com.aerospike:aerospike-client:6.0.0")
```The library doesn't bring transitive dependencies like `vert.x-core` or `aeropspike-client` so you have to install them explicitly.
### Code examples
#### Using old-fashion callback based client
```java
class OldFashionDemo {
@Test
void test(final Vertx vertx, final VertxTestContext context) {
final var nettyEventLoops = new NettyEventLoops(vertx.nettyEventLoopGroup());
final var clientPolicy = new ClientPolicy();
clientPolicy.eventLoops = nettyEventLoops;
final var aerospikeClient = new AerospikeClient(
clientPolicy, aerospike.getHost(), aerospike.getFirstMappedPort());
final var putFuture = Promise.promise();
aerospikeClient.put(null, new WriteListener() {
@Override
public void onSuccess(Key key) {
putFuture.complete(key);
}@Override
public void onFailure(AerospikeException exception) {
putFuture.fail(exception);
}
}, null, new Key(namespace, set, "user1"), new Bin("age", 10));putFuture.future()
.onSuccess(key -> Assertions.assertEquals("user1", key.userKey.toString()))
.flatMap(key -> {
final var getFuture = Promise.promise();
aerospikeClient.get(null, new RecordListener() {
@Override
public void onSuccess(Key key, Record record) {
getFuture.complete(record);
}@Override
public void onFailure(AerospikeException exception) {
getFuture.fail(exception);
}
}, null, key);return getFuture.future();
})
.onSuccess(record -> context.verify(() -> {
Assertions.assertEquals(10L, record.bins.get("age"));
}))
.onComplete(context.succeedingThenComplete());
}
}
```Pros:
* It works
* No extra dependencyCons:
* Verbosity
* Code complexity
* Error prone
* Lack of flexibility#### Using future based client
```java
class NewApiDemo {
@Test
void test(final Vertx vertx, final VertxTestContext context) {
final var nettyEventLoops = new NettyEventLoops(vertx.nettyEventLoopGroup());
final var clientPolicy = new ClientPolicy();
clientPolicy.eventLoops = nettyEventLoops;
final var aerospikeClient = new AerospikeClient(
clientPolicy, aerospike.getHost(), aerospike.getFirstMappedPort());
final var eventLoopSelector = new ContextEventLoop(nettyEventLoops);
final var promiseSelector = new ContextPromiseSelector();
final var asyncAerospike = new VertxAerospikeClient(aerospikeClient, eventLoopSelector, promiseSelector);
asyncAerospike.put(new Key(namespace, set, "user1"), new Bin("age", 10))
.flatMap(asyncAerospike::get)
.onSuccess(it -> context.verify(() -> {
Assertions.assertEquals("user1", it.key().userKey.toString());
Assertions.assertEquals(10L, it.record().bins.get("age"));
}))
.onComplete(context.succeedingThenComplete());
}
}
```Pros:
* Concise syntax driven by Future API
* Ability to provide different event loop selector
* Ability to reduce data concurrency when binding aerospike to vert.x event loopCons:
* Extra dependency