-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Java and Kotlin Getting started #23
Merged
Merged
Changes from 41 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
e01f407
getting started
Yoann-Abbes 891d3d7
fix cast
Yoann-Abbes cf40ae0
@kblondel requested changes
Yoann-Abbes 51e51f5
link bintray
Yoann-Abbes fe1b1d5
update getting started
Yoann-Abbes 5409318
Update doc/1/getting-started/java/index.md
Yoann-Abbes 14ea4ba
Update doc/1/getting-started/java/index.md
Yoann-Abbes 5132317
Update doc/1/getting-started/java/index.md
Yoann-Abbes ba9b572
Update doc/1/getting-started/java/index.md
Yoann-Abbes c4d255b
Update doc/1/getting-started/java/index.md
Yoann-Abbes 935e839
Update doc/1/getting-started/java/index.md
Yoann-Abbes ed14ed2
Update doc/1/getting-started/java/index.md
Yoann-Abbes a53b351
Update doc/1/getting-started/java/index.md
Yoann-Abbes abd0aff
Update doc/1/getting-started/java/snippets/document-java.java
Yoann-Abbes 3be54bd
Update doc/1/getting-started/java/index.md
Yoann-Abbes 4f4ef5b
Update doc/1/getting-started/java/index.md
Yoann-Abbes f251ad4
Update doc/1/getting-started/java/index.md
Yoann-Abbes 1a5629d
Update doc/1/getting-started/java/index.md
Yoann-Abbes 9e47bd2
Update doc/1/getting-started/java/index.md
Yoann-Abbes d4a122e
Update doc/1/getting-started/java/index.md
Yoann-Abbes abd319f
Update doc/1/getting-started/java/index.md
Yoann-Abbes f246fcb
Update doc/1/getting-started/java/index.md
Yoann-Abbes fbf6b78
Update doc/1/getting-started/java/index.md
Yoann-Abbes b289bb2
update getting started kt
Yoann-Abbes b76c2e1
update snippets getting started
Yoann-Abbes a7687ca
Update doc/1/getting-started/java/index.md
Yoann-Abbes 9dfacfc
update getting started
Yoann-Abbes b15f6b8
update document:search signature
Yoann-Abbes 3d94b3f
typo
Yoann-Abbes 13dea72
Update doc/1/getting-started/java/index.md
Yoann-Abbes 94737fd
remove congrats
Yoann-Abbes 00331d8
fix getting started gradle
Yoann-Abbes 3cf3601
fix getting started gradle
Yoann-Abbes 06645f8
search overload
Yoann-Abbes 60ea453
Update doc/1/getting-started/java/snippets/document-java.java
Yoann-Abbes 5d850f7
Update doc/1/getting-started/java/snippets/firstconnection-java.java
Yoann-Abbes 0e4d1e1
Update doc/1/getting-started/java/snippets/realtime-java.java
Yoann-Abbes 92c03ed
Update doc/1/getting-started/kotlin/snippets/document-kotlin.kt
Yoann-Abbes 22f3628
Update doc/1/getting-started/kotlin/snippets/firstconnection-kotlin.kt
Yoann-Abbes 9575ebc
Update doc/1/getting-started/kotlin/snippets/realtime-kotlin.kt
Yoann-Abbes 2540279
fix tab
Yoann-Abbes ce017bd
update getting started java
Yoann-Abbes a5cff10
Update doc/1/getting-started/kotlin/index.md
Yoann-Abbes 48a6996
Update doc/1/getting-started/java/index.md
Yoann-Abbes 661d0aa
update getting started kt
Yoann-Abbes 0a56e04
Update doc/1/getting-started/kotlin/index.md
Yoann-Abbes 8742683
fix tokenexpired
Yoann-Abbes 5c0d8be
Update doc/1/getting-started/kotlin/snippets/realtime-kotlin.kt
Yoann-Abbes d1d6642
@abouthinon requested changes
Yoann-Abbes e4b5475
Update doc/1/getting-started/java/snippets/firstconnection-java.java
Yoann-Abbes a294526
Update doc/1/getting-started/java/snippets/realtime-java.java
Yoann-Abbes 8da633c
Update doc/1/getting-started/kotlin/snippets/document-kotlin.kt
Yoann-Abbes a029905
Update doc/1/getting-started/kotlin/snippets/realtime-kotlin.kt
Yoann-Abbes ce905f0
Update doc/1/getting-started/kotlin/snippets/document-kotlin.kt
Yoann-Abbes b62e09b
Update doc/1/getting-started/kotlin/snippets/firstconnection-kotlin.kt
Yoann-Abbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[snippet-code] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
code: true | ||
type: branch | ||
title: Bulk | ||
description: Bulk Controller | ||
--- | ||
|
||
# Bulk Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
code: false | ||
type: branch | ||
order: 0 | ||
title: Getting Started | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
--- | ||
code: false | ||
type: page | ||
title: Java | ||
description: Java Getting started | ||
order: 99 | ||
--- | ||
|
||
# Getting Started | ||
|
||
In this tutorial you will learn how to install and use the **JVM SDK** for Kuzzle. | ||
This page shows examples of scripts that **store** documents in Kuzzle, and of scripts that subcribe to real-time **notifications** for each new document created. | ||
|
||
::: success | ||
Before proceeding, please make sure your system meets the following requirements: | ||
|
||
- **Oracle JDK or OpenJDK** version 8 or higher ([OpenJDK installation instructions](https://openjdk.java.net/install/)) | ||
- A running Kuzzle Server ([Kuzzle installation guide](/core/2/guides/essentials/installing-kuzzle)) | ||
|
||
::: | ||
|
||
|
||
::: info | ||
Having trouble? Get in touch with us on [Discord](http://join.discord.kuzzle.io)! | ||
::: | ||
|
||
## Installation | ||
|
||
You can find the SDK JARs directly on [bintray](https://bintray.com/kuzzle/maven/sdk-jvm). Download and add them to your classpath. | ||
|
||
::: info | ||
The following examples are made to be executed without any IDE. | ||
If you're using Eclipse, IntelliJ or another Java IDE, you need to add the SDK as a project dependency in your classpath. | ||
::: | ||
|
||
### Installing for Android projects using gradle | ||
|
||
To build the project, add the following lines: | ||
|
||
### Maven | ||
|
||
```xml | ||
<dependency> | ||
<groupId>io.kuzzle</groupId> | ||
<artifactId>sdk-jvm</artifactId> | ||
<version>1.0.0</version> | ||
<type>pom</type> | ||
</dependency> | ||
``` | ||
|
||
### Gradle | ||
|
||
```groovy | ||
repositories { | ||
maven() { | ||
url "https://dl.bintray.com/kuzzle/maven" | ||
} | ||
} | ||
dependencies { | ||
compile 'io.kuzzle:sdk-jvm:1.0.0' | ||
} | ||
``` | ||
|
||
### Ivy | ||
|
||
```html | ||
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.0.0'> | ||
<artifact name='sdk-jvm' ext='pom' ></artifact> | ||
</dependency> | ||
``` | ||
|
||
## First connection | ||
|
||
Initialize a new Java project, create a `GettingStartedFirstConnection.java` file and start by adding the code below: | ||
|
||
<<< ./snippets/firstconnection-java.java | ||
|
||
::: info | ||
If you're not yet familiar with how Kuzzle structures its storage, check our [detailed guide][https://docs.kuzzle.io/core/2/guides/essentials/store-access-data/) | ||
::: | ||
|
||
This program initializes the Kuzzle Server storage by creating an index and a collection. | ||
Run the program with the following command: | ||
|
||
```bash | ||
$ javac -classpath ./path/to/the/sdk.jar GettingStartedFirstConnection.java | ||
$ java -classpath .:./path/to/the/sdk.jar GettingStartedFirstConnection | ||
Connected! | ||
Index nyc-open-data created! | ||
Collection yellow-taxi created! | ||
``` | ||
|
||
You now know how to: | ||
|
||
- Instantiate the Kuzzle SDK and connect to a Kuzzle Server using a specific network protocol (here `websocket`) | ||
- Create an index | ||
- Create a collection within an existing index | ||
|
||
## Create your first document | ||
|
||
Now that you successfully connected to your Kuzzle Server instance, and created an index and a collection, it's time to manipulate documents. | ||
|
||
Here is how Kuzzle structures its storage space: | ||
|
||
- indexes contain collections | ||
- collections contain documents | ||
|
||
Create a `GettingStartedStorage.java` file in the playground and add this code: | ||
|
||
<<< ./snippets/document-java.java | ||
|
||
As you did before, build and run your program: | ||
|
||
```bash | ||
$ javac -classpath ./path/to/the/sdk.jar GettingStartedStorage.java | ||
$ java -classpath .:./path/to/the/sdk.jar GettingStartedStorage | ||
Connected! | ||
New document added to the yellow-taxi collection! | ||
``` | ||
|
||
Many other actions are available to manipulate stored documents. You can check the exhaustive list in the [Document Controller documentation](https://docs.kuzzle.io/sdk/jvm/1/controllers/document). | ||
|
||
Now you know how to: | ||
|
||
- Store documents in a Kuzzle Server, and access to those | ||
|
||
## Subscribe to realtime document notifications (pub/sub) | ||
|
||
Time to use Kuzzle's realtime capabilities. Create a new file `GettingStartedRealtime.java` with the following code: | ||
|
||
<<< ./snippets/realtime-java.java | ||
|
||
This program subscribes to changes made to documents with a `license` field set to `B`, within the `yellow-taxi` collection. Whenever a document matching the provided filters changes, a new notification is received from Kuzzle. | ||
|
||
Build and run your program: | ||
|
||
```bash | ||
$ javac -classpath ./path/to/the/sdk.jar GettingStartedRealtime.java | ||
$ java -classpath .:./path/to/the/sdk.jar GettingStartedRealtime | ||
Connected! | ||
Successfully subscribing! | ||
New document added to yellow-taxi collection! | ||
New created document notification: | ||
|
||
{ | ||
_source={ | ||
birthday=1995-11-27, | ||
license=B, | ||
name=John, | ||
_kuzzle_info={ | ||
createdAt=1605694059151,author=-1 | ||
} | ||
}, | ||
_id=9PDS2nUBeGNr7nwl8j2Q, | ||
_version=1 | ||
} | ||
|
||
``` | ||
|
||
You should see the document content as a `ConcurrentHashMap`. | ||
|
||
Now, you know how to: | ||
|
||
- Create realtime filters | ||
- Subscribe to notifications | ||
|
||
## Where do we go from here? | ||
|
||
Now that you're more familiar with the JVM SDK, you can dive even deeper to learn how to leverage its full capabilities: | ||
|
||
- discover what this SDK has to offer by browsing other sections of this documentation | ||
- learn how to use [pagination strategies](/sdk/jvm/1/core-classes/search-result/next/#pagination-strategies) with the [document:search](/sdk/jvm/1/controllers/document/search/) API action. | ||
- discover others [Kuzzle guides](core/2/guides/essentials/introduction/) | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import io.kuzzle.sdk.*; | ||
import io.kuzzle.sdk.protocol.WebSocket; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class SnippetTest { | ||
private static Kuzzle kuzzle; | ||
|
||
public static void main(String[] args) { | ||
|
||
try { | ||
// Creates a WebSocket connection. | ||
// Replace "kuzzle" with | ||
// your Kuzzle host name (e.g. "localhost") | ||
WebSocket ws = new WebSocket("kuzzle"); | ||
|
||
// Instantiates a Kuzzle client | ||
kuzzle = new Kuzzle(ws); | ||
|
||
// Connects to the server. | ||
kuzzle.connect(); | ||
System.out.println("Connected!"); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
// New document content | ||
ConcurrentHashMap<String, Object> content = new ConcurrentHashMap<>(); | ||
content.put("name", "John"); | ||
content.put("birthday", "1995-11-27"); | ||
content.put("license", "B"); | ||
|
||
// Stores the document in the "yellow-taxi" collection. | ||
try { | ||
kuzzle.getDocumentController() | ||
.create( "nyc-open-data", "yellow-taxi", content).get(); | ||
System.out.println("New document added to the yellow-taxi collection!"); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
// Disconnects the SDK. | ||
kuzzle.disconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: java-gettingstarted#storage | ||
description: Data manipulation | ||
hooks: | ||
before: curl -X POST kuzzle:7512/nyc-open-data/_create ; curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi/; curl -X DELETE kuzzle:7512/nyc-open-data/yellow-taxi/some-id | ||
after: | ||
template: empty | ||
expected: | ||
- Connected! | ||
- New document added to the yellow-taxi collection! |
47 changes: 47 additions & 0 deletions
47
doc/1/getting-started/java/snippets/firstconnection-java.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import io.kuzzle.sdk.*; | ||
import io.kuzzle.sdk.protocol.WebSocket; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class SnippetTest { | ||
private static Kuzzle kuzzle; | ||
|
||
public static void main(String[] args) { | ||
|
||
try { | ||
// Creates a WebSocket connection. | ||
// Replace "kuzzle" with | ||
// your Kuzzle hostname like "localhost" | ||
WebSocket ws = new WebSocket("kuzzle"); | ||
|
||
// Instantiates a Kuzzle client | ||
kuzzle = new Kuzzle(ws); | ||
|
||
// Connects to the server. | ||
kuzzle.connect(); | ||
System.out.println("Connected!"); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
// Freshly installed Kuzzle servers are empty: we need to create | ||
// a new index. | ||
try { | ||
kuzzle.getIndexController().create("nyc-open-data").get(); | ||
System.out.println("Index nyc-open-data created!"); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
// Creates a collection | ||
try { | ||
kuzzle.getCollectionController().create("nyc-open-data", "yellow-taxi").get(); | ||
System.out.println("Collection yellow-taxi created!"); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
// Disconnects the SDK | ||
kuzzle.disconnect(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably come earlier, before we make the user create an index and a collection. It'd probably be better to also link to a more detailed guide page, such as https://docs.kuzzle.io/core/2/guides/essentials/store-access-data/
That would give something like this (to be moved to the previous chapter):