Giter Club home page Giter Club logo

mca-integration-demo's Introduction

Couchbase Java Multi Cluster Integration Demo

This project demonstrates the integration of the Java MCA library with spring / spring boot.

The "glue" code is found under the internal package, but the rest under the main com.couchbase.spring.mca is just application level code that can be customized.

The code demos how to use both the template and the repository to perform operations which are backed by the underlying MCA library. Coordinator and failure detector can (and should) be customized in the MultiClusterDatabaseConfiguration class.

@Configuration
public class MultiClusterDatabaseConfiguration extends AbstractMultiClusterConfiguration {

  @Bean
  @Override
  public String bucketName() {
    return "travel-sample";
  }

  @Override
  public String userName() {
    return "Administrator";
  }

  @Override
  public String userPass() {
    return "password";
  }

  @Bean
  @Override
  public Coordinator coordinator() {
    return Coordinators.isolated(new IsolatedCoordinator.Options());
  }

  @Bean
  public FailureDetectorFactory<? extends FailureDetector> failureDetectorFactory() {
    return FailureDetectors.nodeHealth(coordinator(), NodeHealthFailureDetector.options());
  }

}

the beans can then be autowired as usual:

@SpringBootApplication
@Controller
public class Application {

  @Autowired
  private CouchbaseTemplate template;

  @Autowired
  private AirportRepository repository;

  @GetMapping("/airports/{id}")
  public ResponseEntity<Airport> read(@PathVariable String id) {
    Airport airport =  template.findById("airport_" + id, Airport.class);
    return new ResponseEntity<>(airport, HttpStatus.OK);
  }

  @GetMapping("/airports")
  public ResponseEntity<Iterable<Airport>> readAll() {
    return new ResponseEntity<>(repository.findAll(), HttpStatus.OK);
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}

mca-integration-demo's People

Contributors

daschl avatar

Watchers

James Cloos avatar Jose Molina avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.