Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents


Micronaut is a microservice microservice framework for building modular applications. This develops a module to configure and setup ignite to work with Micronaut and it's associated API's.

AutoConfiguration

IgniteClientConfiguration

configuration that bests works with Micronaut.

Documentation: https://micronaut-projects.github.io/micronaut-ignite/snapshot/guide/

Releases: https://github.com/micronaut-projects/micronaut-ignite/releases

Auto-Configuration

Micronaut can span an instance of Ignite automatically. Below we review several configuration options.

Ignite Thick Clients

Ignite Thick Client Bean Configuration

A thick client bean can be configured via the application properties file as follows:Configuration to load Ignite instance.

Code Block
languagejavayml
titleIgniteClientConfiguration
collapsetrue
example config
ignite: 
	enabled: true
	client-mode: true
	discovery-spi:
		static-ip-finder:
			enabled: true
			addresses:
			- "127.0.0.1:47500"
			- "127.0.0.1:47501"


Instead of the static IP finder, you can enable the Kubernetes one if a Micronaut app is deployed in a K8S environment:

Code Block
languageyml
titleexample config
ignite: 
	enabled: true
    client-mode: true
	discovery-spi:
		kubernetes-ip-finder:
			enabled: true
			namespace: default
			service-name: ignite


Additional configuration can be applied on top of the default configuration by intercepting the bean when its created, Using the BeanCreatedEventListener.

Code Block
languagejava

@Singleton
public class IgniteConfigurationFactoryInterceptor implements BeanCreatedEventListener<DefaultIgniteConfiguration> {
    @Override
    public DefaultIgniteConfiguration onCreated(BeanCreatedEvent<DefaultIgniteConfiguration> event
/**
 * Ignite cache configuration.
 */
@EachProperty(value = IgniteClientConfiguration.PREFIX + ".clients", primary = "default")
public class IgniteClientConfiguration implements Named {
    public static final String PREFIX = "ignite";

    private final String name;
    private String path;

    /**
     * @param name Name or key of the client.
     */
    public IgniteClientConfiguration(@Parameter String name) {
        this.name = name;
    }

    /**
     * path to load in bean configuration.
     *
     * @param path bean config to load.
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * path to load in bean configuration.
     *
     * @return bean config to load.
     */
    public String getPath() {
        return pathDefaultIgniteConfiguration configuration = event.getBean();
    }

    /**
     * @return name or key for client
     */
    @NonNull
    @Override
    public String getName() {configuration.setIgniteInstanceName("instance-a");
        return this.nameconfiguration;
    }
}

...

Ignite Cache Configuration


Code Block
languageyml
titleexample config
ignite: 
	enabled: true
	clients:
		default:
	cache-configurations:
		name:
			group-name: string
			onheap-cache: boolean
			sql-onheap-cache: boolean
			patheager-ttl: "classpath:a.cfg"         
		other:            boolean
			cache-mode: LOCAL | REPLICATED | PARTITIONED
			rebalance-mode: SYNC | ASYNC | NONE
			data-region-name: string
			path: "classpath:b.cfg"

  • default is the primary bean
  • path loads in a spring bean definition

Application factory configuration

A bean for the IgniteConfiguration can be provided from a factory.

...

key-type: java.Object
			value-type: java.Object
		second:
			group-name: two


Code Block
languagejava
titleexample config
@Factory
public class IgniteInitial configurationFactory(){

    @Singleton
    @Bean
    @Primary@IgnitePrimary
    @Named("default")
    IgniteConfiguration defaultConfigurationCacheConfiguration<String,String> cacheInstance() {
        IgniteConfigurationreturn cfgnew = new IgniteConfiguration();

        // The node will be started as a client node.
        cfg.setClientMode(trueCacheConfiguration<String, String>("my-cache")
            .setBackups(10);
        // Setting up an IP Finder to ensure the client can locate the servers.
        TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();}
}
			

Ignite Thin Clients - WIP


Code Block
languageyml
titleThin Client Configuration
ignite-thin-client:
  enabled: true
  addresses:
        ipFinder.setAddresses(Collections.singletonList("localhost:47500..47509"));- "127.0.0.1:10800"
        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
        return cfg;
    }
}

Micronaut Caching API

- "127.0.0.1:10801"

Micronaut Ignite Cache

Micronaut cache Micronaut cache configuration is covered under snapshot documentation. By default, the primary Ignite instance is used for Micronaut cache and the key from for each cache operation will use name of refer to the IgniteCache instance.

Code Block
languagejava
titleIgniteCacheManager
collapsetrue
@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.

...

languagejava
titleExample Cacheable Object
collapsetrue

...


Micronaut Ignite Application

https://github.com/pollend/micronaut-ignite-sample

...