...
Micronaut is a microservice framework for building moudlar applications. This develops a configuration that bests works with Micronaut.
Auto-Configuration
...
Minimum Configuration
Code Block |
---|
language | yml |
---|
title | example config |
---|
|
ignite:
enabled: true
comunication-spi:
local-port: 5555
|
Ignite Cache Configuration
Code Block |
---|
language | yml |
---|
title | example config |
---|
|
ignite:
enabled: true
cache-configurations:
accountsname:
tablegroup-name: ACCOUNTS: string
onheap-cache: boolean
sql-onheap-cache: boolean
keyeager-typettl: Stringboolean
cache-mode: LOCAL | REPLICATED | books:PARTITIONED
rebalance-mode: SYNC | ASYNC | NONE
tabledata-region-name: BOOKSstring
key-type: java.Object
value-type: java.Object
second:
group-name: String
|
...
Code Block |
---|
language | java |
---|
title | example config |
---|
|
@Factory
public class configurationFactory(){
@Singleton
@Bean
@IgnitePrimary
CacheConfiguration<String,String> cacheInstance() {
return new CacheConfiguration<String, String>("my-cache")
.setBackups(10);
}
}
|
Ignite discovery-spi Configuration
kubernetes
Code Block |
---|
language | yml |
---|
title | example config |
---|
|
ignite:
enabled: true
discovery-spi:
kubernetes-ip-finder:
enabled: trued
namespace: default
service-name: ignite
|
static-ip-finder
Code Block |
---|
language | yml |
---|
title | example config |
---|
|
ignite:
enabled: true
discovery-spi:
static-ip-finder:
enabled: true
addresses:
- 127.0.0.1:47500
- 127.0.0.1:47501 |
Ignite factory configuration
...
Code Block |
---|
language | java |
---|
title | IgniteCacheManager |
---|
collapse | true |
---|
|
@Singleton
public class IgniteCacheManager implements DynamicCacheManager<IgniteCache> {
private final Ignite ignite;
private final ConversionService<?> service;
private final ExecutorService executorService;
public IgniteCacheManager(@Primary Ignite ignite,
ConversionService<?> service,
@Named(TaskExecutors.IO) ExecutorService executorService) {
this.ignite = ignite;
this.service = service;
this.executorService = executorService;
}
@NonNull
@Override
public SyncCache<IgniteCache> getCache(String name) {
return new IgniteSyncCache(service, ignite.getOrCreateCache(name), executorService);
}
}
|
Example
This is an example of a service using Micronaut Cache.
Code Block |
---|
language | java |
---|
title | Example Cacheable Object |
---|
collapse | true |
---|
|
@Singleton
@CacheConfig('counter')
static class CounterService {
Map<String, Integer> counters = new LinkedHashMap<>()
Map<String, Integer> counters2 = new LinkedHashMap<>()
int incrementNoCache(String name) {
int value = counters.computeIfAbsent(name, { 0 })
counters.put(name, ++value)
return value
}
@CachePut
int increment(String name) {
int value = counters.computeIfAbsent(name, { 0 })
counters.put(name, ++value)
return value
}
@PutOperations([
@CachePut('counter'),
@CachePut('counter2')
])
int increment2(String name) {
int value = counters2.computeIfAbsent(name, { 0 })
counters2.put(name, ++value)
return value
}
@Cacheable
CompletableFuture<Integer> futureValue(String name) {
return CompletableFuture.completedFuture(counters.computeIfAbsent(name, { 0 }))
}
@Cacheable
@SingleResult
Flowable<Integer> flowableValue(String name) {
return Flowable.just(counters.computeIfAbsent(name, { 0 }))
}
@Cacheable
Single<Integer> singleValue(String name) {
return Single.just(counters.computeIfAbsent(name, { 0 }))
}
@CachePut
CompletableFuture<Integer> futureIncrement(String name) {
int value = counters.computeIfAbsent(name, { 0 })
counters.put(name, ++value)
return CompletableFuture.completedFuture(value)
}
@Cacheable
int getValue(String name) {
return counters.computeIfAbsent(name, { 0 })
}
@Cacheable('counter2')
int getValue2(String name) {
return counters2.computeIfAbsent(name, { 0 })
}
@Cacheable
Optional<Integer> getOptionalValue(String name) {
return Optional.ofNullable(counters.get(name))
}
@CacheInvalidate(all = true)
void reset() {
counters.clear()
}
@CacheInvalidate
void reset(String name) {
counters.remove(name)
}
@InvalidateOperations([
@CacheInvalidate('counter'),
@CacheInvalidate('counter2')
])
void reset2(String name) {
counters.remove(name)
}
@CacheInvalidate(parameters = 'name')
void set(String name, int val) {
counters.put(name, val)
}
} |
Micronaut Ignite Application
...