git clone https://github.com/migratorydata/getting-started-cpp-client-api.git
include/config.h
// For API documentation go to [Developer s Guide](https://migratorydata.com/docs/client-api/cpp/) #include <string> static bool ENCRYPTION = true; static std::string TOKEN = "{{ token }}"; static std::string SERVER = "{{ server }}"; static std::string SUBJECT = "{{ endpoint.endpoint }}";
build.bat start.bat
SUB
PUB
e.g.
npm init --yes
npm install migratorydata-client@~6.0.1
sample-client.js
// For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/nodejs/) require("migratorydata-client"); function publish() { var date = new Date(); var time = date.getTime(); var message = { subject : "{{ endpoint.endpoint }}", content : "content-" + time, closure : "id-" + time }; client.publish(message); } var client = new MigratoryDataClient(); // uncomment next line for setups using load balancing with DNS round-robin //client.setDnsOptions({dnsResolve: true}); client.setMessageHandler(function(message) { console.log("Got message : [" + message.subject + " = " + message.content + "]"); }); client.setStatusHandler(function(event) { console.log("Status : " + event.type + " : " + event.info); // in this example, publication starts once it gets NOTIFY_SERVER_UP if (event.type == MigratoryDataClient.NOTIFY_SERVER_UP) { publish(); } // normally, next publication should be performed once the client gets // the status of the previous publication if (event.type == MigratoryDataClient.NOTIFY_PUBLISH_OK) { // publish a new message after let's say 1000 milliseconds setTimeout(function() { publish(); }, 1000); } if (event.type == MigratoryDataClient.NOTIFY_PUBLISH_FAILED) { // normally the previous message should be republished here } if (event.type == MigratoryDataClient.NOTIFY_PUBLISH_DENIED) { console.log("Check your entitlement token"); } }); client.setEntitlementToken("{{ token }}"); client.setServers([ "https://{{ server }}" ]); client.subscribe([ "{{ endpoint.endpoint }}" ]); client.connect();
node sample-client.js
git clone https://github.com/migratorydata/getting-started-python-client-api.git
sample/config.py
# For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/python/) class Config: server = ["{{ server }}"] encryption = True subject = "{{ endpoint.endpoint }}" token = "{{ token }}"
python sample
git clone https://github.com/migratorydata/getting-started-java-client-api.git
src/main/java/com/migratorydata/example/Config.java
// For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/java/) package com.migratorydata.example; public class Config { public static final boolean encryption = true; public static final String[] server = new String[] {"{{ server }}"}; public static final String subject = "{{ endpoint.endpoint }}"; public static final String token = "{{ token }}"; }
./gradlew clean build ./gradlew run
dotnet new console -n getting-started-csharp-client-api
dotnet add package MigratoryData.Client.DotNet --version 6.0.1
Program.cs
// For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/ios/) using System; using System.Collections.Generic; using com.migratorydata.client; using System.Threading; namespace example { class Program { static void Main(string[] args) { MigratoryDataClient client = new MigratoryDataClient(); client.SetLogListener(new LogList(), MigratoryDataLogLevel.DEBUG); client.SetListener(new Listener()); client.SetEncryption(true); client.SetEntitlementToken("{{ token }}"); client.SetServers(new string[] { "{{ server }}" }); List<string> subjects = new List<string>(); subjects.Add("{{ endpoint.endpoint }}"); client.Subscribe(subjects); client.Connect(); // publish a message every 3 seconds int count = 1; while (count < 1000000) { client.Publish(new MigratoryDataMessage("{{ endpoint.endpoint }}", System.Text.Encoding.ASCII.GetBytes("data - " + count), "id" + count)); count++; Thread.Sleep(3000); } } class Listener : MigratoryDataListener { public void OnMessage(MigratoryDataMessage message) { System.Console.WriteLine(message.ToString()); } public void OnStatus(string status, string info) { System.Console.WriteLine(status + " " + info); } } class LogList : MigratoryDataLogListener { public void OnLog(string log, MigratoryDataLogLevel level) { string msg = string.Format("[{0:G}] [{1}] {2}", DateTime.Now, level, log); Console.WriteLine(msg); } } } }
dotnet run
composer require migratorydata/migratorydata-client-php:6.*
sample-client.php
<?php // For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/php/) require __DIR__ . '/vendor/autoload.php'; use MigratoryData\Client\MigratoryDataClient; use MigratoryData\Client\MigratoryDataException; use MigratoryData\Client\MigratoryDataMessage; // Create a MigratoryData client $client = new MigratoryDataClient(); try { // Attach the entitlement token to the client. $client->setEntitlementToken("{{ token }}"); // Connect to a MigratoryData server $client->setServers(array("https://{{ server }}")); $client->connect(); } catch (MigratoryDataException $e) { // Exceptions with one of the error codes: // E_INVALID_URL_LIST // E_CLUSTER_MEMBERS_CONNECTION_FAILED // E_ENTITLEMENT_TOKEN // E_RUNNING // See the documenation of MigratoryDataException for more details echo("Exception: " . $e->getDetail() . "\n"); exit(1); } while (true) { // Publish a message try { $message = new MigratoryDataMessage("{{ endpoint.endpoint }}", time()); $response = $client->publish($message); echo("Got response: " . $response . "\\n"); } catch (MigratoryDataException $e) { // Exception with one of the error codes: // E_NOT_CONNECTED // E_MSG_NULL // E_MSG_INVALID // E_INVALID_SUBJECT // E_INVALID_PROTOCOL // See the documentation of MigratoryDataException for more details echo("Exception: " . $e->getDetail() . "\\n"); } sleep(3); }
php sample-client.php
TOKEN={{ token }} curl -d "some message" -X POST "https://{{ server }}/rest/produce?token=${TOKEN}&subject={{ endpoint.endpoint }}"
composer require migratorydata/migratorydata-client-reactphp:6.*
<?php // For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/reactphp/) require __DIR__ . '/vendor/autoload.php'; use MigratoryData\Client\MigratoryDataClient; use MigratoryData\Client\MigratoryDataException; use MigratoryData\Client\MigratoryDataMessage; use MigratoryData\Client\MigratoryDataListener; class MyListener implements MigratoryDataListener { public function onMessage($message) { echo "Got message: " . $message . "\\n"; } public function onStatus($status, $info) { echo "Got status: " . $status . " - " . $info . "\\n"; } } $loop = \React\EventLoop\Factory::create(); $client = new MigratoryDataClient(); $client->setEntitlementToken("{{ token }}"); $client->setLoop($loop); $client->setListener(new MyListener()); try { $client->setServers(array("https://{{ server }}")); } catch (MigratoryDataException $e) { echo($e->getDetail()); exit(1); } $client->subscribe(array("{{ endpoint.endpoint }}")); $client->connect(); $loop->addPeriodicTimer(3, function () use ($client) { try { $client->publish(new MigratoryDataMessage("{{ endpoint.endpoint }}", "Msg " . time(), "closure-" . time())); } catch (MigratoryDataException $e) { echo($e->getDetail()); echo($e->getCause()); } }); $loop->run();
git clone https://github.com/migratorydata/getting-started-android-client-api.git
com.migratorydata.androidexampleapplication.Config
// For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/android/) package com.migratorydata.androidexampleapplication; public class Config { public static final boolean encryption = false; public static final String[] server = new String[] {"{{ server }}"}; public static final String subject = "{{ endpoint.endpoint }}"; public static final String token = "{{ token }}"; }
https://github.com/migratorydata/getting-started-ios-client-api.git
sample-client/Config.m
// For API documentation go to [Developer’s Guide](https://migratorydata.com/docs/client-api/ios/) #import <Foundation/Foundation.h> BOOL ENCRYPTION = YES; NSString *TOKEN = @"{{ token }}"; NSString *SERVER = @"{{ server }}"; NSString *SUBJECT = @"{{ endpoint.endpoint }}";
{{ endpoint.endpoint }}
{{ token }}