javaone 2017 - choosing a nosql api and database to avoid tombstones and dragons in game on!...
TRANSCRIPT
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Choosing a NoSQL API and Database to Avoid Tombstones and Dragons
in Game On!
Leonardo Lima Otávio SantanaKate Stanley
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
About the Speakers
Katherine (Kate) Stanley
• Software Engineer, works for IBM
• From United Kingdom
• Work on Java development for IBM Cloud
• Committer to Game On
• Contributed to MicroProfile conference app
• Co-wrote IBM Redbook about Microservices with Java
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
About the Speakers
Leonardo Lima
• Computer engineer, server & embedded sw developer
• From São Paulo, Brasil, currently in Austin, TX
• CTO at V2COM
• Spec Lead – JSR363 – Units of Measurement
• V2COM’s Representative at JCP Executive Committee
[about.me/leomrlima]
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Otávio Santana
• Software engineer, Tomitribe
• From Salvador, Brazil
• Java Champion, SouJava JUG Leader
• Apache, Eclipse and OpenJDK Committer
• Expert Group member in many JSRs
• Representative at JCP EC for SouJava
About the Speakers
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Microservices & GameOn!
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Microservices are used to…
� … compose a complex application using:◦ “small”
◦ independent (autonomous)
◦ replaceable
◦ processes
� … that communicate via language-agnostic APIs
Microservice
MicroserviceMicroservice
Microservice
Microservices application
Subscribe
REST(JSON/HTTP)
Microservice
Microservice
broker
API
MicroservicePublish
API
REST(JSON/HTTP)
Publish
ServiceRegistry
API
Microservice
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Microservices sample apps…
Create a single service
Rebuild a pre-baked microservices application
CluelessNo idea
ConfidentHas read all the
things!
ExperiencedHands-on understanding
Puzzled / RealisticChallenges are real
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Enter… GameOn!
� Hands on with microservices
� Stick with ’Hello World’ simplicity
� Choose your own adventure
� Fast path to the hard stuff
� Build something cool (to you!)
� Learn as you go
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Twelve Factors
� “a methodology for building software-as-a-service applications”
◦ Created by developers at Heroku
� Factors are independent of
◦ programming language,
◦ backing services,
◦ cloud provider
� http://12factor.net/
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
At first…
ELK mongo
room
Player
Proxy
JSON/HTTP (REST)
Concierge
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
… and now!
kafkaELK amalgam8couchdb
room
PlayerAuth
SweepProxystatic
MediatorMap
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
About Dragons and Tombstones
� Problem: Maintaining a centered, densely packed grid of rooms
� SQL is hard.� CouchDB uses javascript to create
custom indexes� BUT: Deleting rooms leaves
tombstones. They never go away.
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
The Map API
� Site has Name, Position (X, Y), Connection information to the WebService and a list of its Doors.
� CRUD service; when you retrieve a room, you get a list of its adjacent rooms
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
The Map API{
"name":"First Room","connectionDetails":{
…, "target":"ws://secondroom:9008/barn/ws",… },
"fullName":"The First Room","description":"A helpful room with doors in every possible direction.","repositoryUrl":"https://github.com/your-fork","doors":{
"n":"A knobbly wooden door with a rough carving or a friendly face","w":"A fake wooden door with stickers of friendly faces plastered all over it","s":"A warped wooden door with a friendly face branded on the corner","e":"A polished wooden door with an inlaid friendly face",
}}
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
The Map Internals, version 1
� Literally a copy of what’s exposed� Hard to store references to other rooms
� Room pre-allocation and movement make it cumbersom� No way to (really) delete rooms (!)
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Map.stream().toGraph()
� A Map is a Collection of Rooms connected thru Doors� X connected to Y is… a graph!
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
A graph, really?
First Room
Play Room
Basement
Dungeon
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Take 1: Neo4J
� Created rooms using Neo4J APIs and Cypher query language� No easy way to do CRUD operations◦ Convert from object to Cypher using inspection
� In the end, just changing who was holding our chain…
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Take 2: JNoSQL!
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
What is JNoSQL?
� Mapping API - Artemis
� Communication API - Diana
� No lock-in
� Divide and conquer
DAO
Communication
Mapping
JNoS
QL
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Eclipse JNoSQL
� Eclipse Foundation� Apache v2 + EPL 1.0
� API to each NoSQL type� Configurable� Extensible Communication
Mapping
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
JNoSQL – Diana APIs
Key/Value Document
Column Family
Graph
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Names & Definitions
� Annotated Entities� Template� Repository� Configuration
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Annotaded Entities
� MappedSuperclass� Entity� Column
@Entitypublic class Site {
@Idprivate Long id;
@Columnprivate String name;
…}
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Template
@Injectprivate GraphTemplate template;
public Optional<Site> getRecentRoom() {return template.getTraversalVertex().has("doorAvailable", true).<Site>stream().sorted(ORDER_WEIGHT).findFirst();
}
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Repository
public interface SiteRepository extends Repository<Site, Long> {Optional<Site> findByName(String name);
}
@Inject@Database(GRAPH)private SiteRepository repository;
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Repository@Transactionalpublic void save(Site site) {
if (isNull(site.getId())) {Optional<Site> siteByName = repository.findByName(site.getName());siteByName.ifPresent(site::merge);
}repository.save(site);
}
public Optional<Site> findByName(String name) {return repository.findByName(name);
}
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
The future & possibilities
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Why a graph makes MUCH sense?
� Current 2D map is VERY limiting◦ With a graph we can go 3D!
� Different kinds of objects can be tracked: ◦ Items can be made unique and migrate
� Other doors are possible!
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Why a graph makes MUCH sense?
First Room
Play Room
Basement
Dungeon
The One Ring
Suite
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Get involved!
� https://gameontext.slack.com� https://gameontext.org� http://jnosql.org� https://github.com/leomrlima/gameon-graph-map
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
? & !
GameOn
! + JNoSQL
#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava
Thanks!