Skip to content
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

KZL-1054 Fix Node.js SDK Getting Started subscription #257

Merged
merged 10 commits into from
Mar 25, 2019
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ if (options.dev.enabled) {
metalsmith
.use(
serve({
port: 3000,
port: parseInt(process.env.PORT) || 3000,
verbose: false,
host: 'localhost'
})
Expand Down Expand Up @@ -318,4 +318,4 @@ if (!options.dev.enabled) {
}
log(ok + ' Build finished');
});
}
}
11 changes: 6 additions & 5 deletions src/guide/1/essentials/installing-kuzzle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ The following operating systems are actively supported (64-bit versions only):

* [Elasticsearch](https://www.elastic.co/products/elasticsearch) version 5.x
* [Redis](http://redis.io/) version 3.x
* [Node.js](https://nodejs.org/en/download/package-manager/) version 6.x or higher.
* [NPM](https://www.npmjs.com/) version 3 or higher.
* [Python](https://www.python.org/) version 2.7 preferred.
* [GDB](https://www.gnu.org/software/gdb/) version 7.7 or higher.
* a C++11 compatible compiler.
* [Node.js](https://nodejs.org/en/download/package-manager/) version 6.x or higher
* [NPM](https://www.npmjs.com/) version 3 or higher
* [Python](https://www.python.org/) version 2.7 preferred
* [GDB](https://www.gnu.org/software/gdb/) version 7.7 or higher
* a C++11 compatible compiler
* it's strongly advised that the system value for the maximum number of opened files (`ulimit -n` on most Unix systems) is set to a high value (i.e. 65535 is a good min. value)

<div class="alert alert-info">
The last three prerequisites can be fulfilled on Debian-based systems by installing packages : <code>build-essential</code>, <code>gdb</code> and <code>python</code>.
Expand Down
6 changes: 3 additions & 3 deletions src/guide/1/getting-started/first-steps/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Before proceeding, please make sure your system has these programs installed:
* **Node.js** version 6 or higher (<a href="https://nodejs.org/en/download/">instructions here</a>)
* Kuzzle

### Prepare your environment
## Prepare your environment

Create your playground directory and install the [Javascript SDK]({{ site_base_path }}sdk-reference) from the command line using npm:

Expand Down Expand Up @@ -67,7 +67,7 @@ Congratulations! You are now ready to say Hello to the World!
Having trouble? Get in touch with us on <a href="https://gitter.im/kuzzleio/kuzzle">Gitter!</a> We're happy to help.
</div>

### Create your first "Hello World" document
## Create your first "Hello World" document

Create a `create.js` file with the following code:

Expand Down Expand Up @@ -102,7 +102,7 @@ Having trouble? Get in touch with us on <a href="https://gitter.im/kuzzleio/kuzz

_You can find more resources about Kuzzle SDK in the [SDK Reference]({{ site_base_path }}sdk-reference)._

### Subscribe to data changes (pub/sub)
## Subscribe to data changes (pub/sub)

Kuzzle provides pub/sub features that can be used to trigger real-time notifications based on the state of your data (for a deep-dive on notifications check out the **Room** class definition in the <a href="{{ site_base_path }}sdk-reference">SDK Reference</a>).

Expand Down
57 changes: 29 additions & 28 deletions src/sdk-reference/cpp/1/getting-started/snippets/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,37 @@
#include "kuzzle.hpp"

int main(int argc, char * argv[]) {
// Instanciate a Kuzzle client
// with a WebSocket connection.
// Replace "kuzzle" with
// your Kuzzle hostname like "localhost"
Kuzzle *kuzzle = new kuzzleio::Kuzzle(new kuzzleio::WebSocket("kuzzle"));
// Instantiate a Kuzzle client with a WebSocket connection.
// Replace "kuzzle" with your actual Kuzzle hostname (e.g. "localhost")
kuzzleio::WebSocket * ws = new kuzzleio::WebSocket("kuzzle");
kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle(ws);

try {
// Connects to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;
}
catch(KuzzleException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}
try {
// Connect to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;
}
catch(kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}

try {
// Get server current date as UNIX timestamp.
std::cout << "Server current timestamp: "
<< kuzzle->server->now()
<< std::endl;
}
catch(KuzzleException &e) {
std::cerr << e.what() << std::endl;
kuzzle->disconnect();
exit(1);
}

// Disconnects the SDK.
try {
// Get the server current date as a UNIX timestamp.
std::cout << "Server current timestamp: "
<< kuzzle->server->now()
<< std::endl;
}
catch(kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
kuzzle->disconnect();
exit(1);
}

// Disconnect and free resources
kuzzle->disconnect();
delete kuzzle;
delete ws;

return 0;
return 0;
}
89 changes: 45 additions & 44 deletions src/sdk-reference/cpp/1/getting-started/snippets/document.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
#include <iostream>

#include "kuzzle.hpp"
#include "websocket.hpp"

#define K_INDEX_NAME "nyc-open-data"
#define K_COLLECTION_NAME "yellow-taxi"


int main(int argc, char * argv[]) {
std::string res;
// Instanciate a Kuzzle client
// with a WebSocket connection.
// Replace "kuzzle" with
// your Kuzzle hostname like "localhost"
Kuzzle *kuzzle = new kuzzleio::Kuzzle(new kuzzleio::WebSocket("kuzzle"));
try {
// Connects to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;
}
catch(KuzzleException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}

// New document content
std::string document = R"(
{
"name": "Sirkis",
"birthday": "1959-06-22",
"license": "B"
}
)";

try {
// Stores the document in the "yellow-taxi" collection.
res = kuzzle->document->create(K_INDEX_NAME, K_COLLECTION_NAME, "some-id", document);
std::cout << "Document created successfuly: " << res << std::endl;
}
catch(KuzzleException &e) {
std::cerr << e.what() << std::endl;
kuzzle->disconnect();
exit(1);
// Instantiate a Kuzzle client with a WebSocket connection.
// Replace "kuzzle" with your actual Kuzzle hostname (e.g. "localhost")
kuzzleio::WebSocket *ws = new kuzzleio::WebSocket("kuzzle");
kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle(ws);

try {
// Connect to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;
}
catch(kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}

// New document content
std::string document = R"(
{
"name": "Sirkis",
"birthday": "1959-06-22",
"license": "B"
}

// Disconnects the SDK.
kuzzle->disconnect();

return 0;
)";

try {
// Store the document in the "yellow-taxi" collection, itself in the
// "nyc-open-data" data index
std::string response = kuzzle->document->create(
"nyc-open-data",
"yellow-taxi",
"document-id",
document);
std::cout << "Document created successfully: " << response << std::endl;
}
catch(kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}

// Disconnect and free allocated resources
kuzzle->disconnect();

delete kuzzle;
delete ws;

return 0;
}
71 changes: 31 additions & 40 deletions src/sdk-reference/cpp/1/getting-started/snippets/init.cpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
#include <iostream>

#include "kuzzle.hpp"
#include "websocket.hpp"

#define K_INDEX_NAME "nyc-open-data"
#define K_COLLECTION_NAME "yellow-taxi"


int main(int argc, char * argv[]) {
// Instanciate a Kuzzle client
// with a WebSocket connection.
// Replace "kuzzle" with
// your Kuzzle hostname like "localhost"
Kuzzle *kuzzle = new kuzzleio::Kuzzle(new kuzzleio::WebSocket("kuzzle"));

try {
// Connects to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;

// Freshly installed Kuzzle servers are empty: we need to create
// a new index.
kuzzle->index->create(K_INDEX_NAME);
std::cout << "Index "
<< K_INDEX_NAME
<< " created!"
<< std::endl;

// Creates a collection
kuzzle->collection->create(K_INDEX_NAME, K_COLLECTION_NAME);
std::cout << "Collection "
<< K_COLLECTION_NAME
<< " created!"
<< std::endl;
}
catch(KuzzleException e) {
std::cerr << e.what() << std::endl;
exit(1);
}

// Disconnects the SDK
kuzzle->disconnect();

return 0;
// Instantiate a Kuzzle client with a WebSocket connection.
// Replace "kuzzle" with your actual Kuzzle hostname (e.g. "localhost")
kuzzleio::WebSocket *ws = new kuzzleio::WebSocket("kuzzle");
kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle(ws);

try {
// Connect to the server.
kuzzle->connect();
std::cout << "Connected!" << std::endl;

// Freshly installed Kuzzle servers are empty: we first need to create
// a data index. The one used in this example is named "nyc-open-data"
kuzzle->index->create("nyc-open-data");
std::cout << "Index nyc-open-data created!" << std::endl;

// Create a data collection named "yellow-taxi" in our newly created index
kuzzle->collection->create("nyc-open-data", "yellow-taxi");
std::cout << "Collection yellow-taxi created!" << std::endl;
}
catch(kuzzleio::KuzzleException e) {
std::cerr << e.what() << std::endl;
exit(1);
}

// Disconnect and free allocated resources
kuzzle->disconnect();

delete kuzzle;
delete ws;

return 0;
}

Loading