Skip to content

KrzysztofKowalczyk/micronaut-couchbase-example

Repository files navigation

Example of using Couchbase in Micronaut

This project requires Java and docker to be available.

./gradlew test

To run tests.

Direct couchbase usage (no micronaut)

First have a look at DirectCouchbaseTest which configures couchbase client manually. Couchbase SDK went through complete rewrite betwee 2.x and 3.x branches, hence don't use the old one as migration can be painful.

This class extends a AbstractCouchbaseTest which setup a whole instance of Couchbase running inside docker image. It is using https://www.testcontainers.org/ but I am not reusing existing Couchbase image as it clashed with Micronaut and/or new SDK. It creates an instance with values hardcoded in initCluster.sh.

Using micronaut to configure and inject Couchbase components

In this case the setup of Couchbase is done more in Micronaut-way, but still using custom defined classes.

Eventually you can simply inject Couchbase Collection like it is done in MicronautCouchbaseTest

Couchbase components are provided for injection in CouchbaseFactory, which is normal Micronaut dependency injection.

Configuration is provided through static and immutable way using CouchbaseConfiguration interface. This interface takes properties according to Micronaut convetion mapping from multiple sources.

In this example those are 4 different sources:

  • couchbase.username - provided explicitly using @Property annotation on the test class
  • couchbase.password - provided by explicitly by point to config file
  • couchbase.host - default value defined on CouchbaseConfiguration
  • couchbase.default-bucket-name - provided automatically by env specific properties file: application-test.yaml

File sources can be defined using yaml, json or .property format. See Micronaut propertySource for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published