From b374b3a7ca96f1b115a55dc8ef21b4a1feaff807 Mon Sep 17 00:00:00 2001 From: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> Date: Wed, 11 Aug 2021 18:22:36 +0100 Subject: [PATCH 1/2] Update Java codeblocks for the quickstart --- content/root/quick-start-guide.textile | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/content/root/quick-start-guide.textile b/content/root/quick-start-guide.textile index 321f332080..c8af50ef5b 100644 --- a/content/root/quick-start-guide.textile +++ b/content/root/quick-start-guide.textile @@ -93,20 +93,32 @@ blang[php]. bc[php]. require_once __DIR__ . '/../vendor/autoload.php'; blang[java]. - The Ably Client Library SDK is hosted on "GitHub":https://github.com/ably/ably-java. + The Ably Client Library SDK is available on "GitHub":https://github.com/ably/ably-java and hosted on "Maven Central":https://mvnrepository.com/repos/central. - To get started with your project, add the SDK into your @build.gradle@ dependencies section. + To get started with your project, add the SDK into your @build.gradle@ dependencies section and a reference to Maven in the repositories section if it isn't included by default. For Java applications: ```[java] - compile 'io.ably:ably-java:1.2.0' + dependencies { + implementation 'io.ably:ably-java:1.2.0' + } + + repositories { + mavenCentral() + } ``` For Android apps: ```[java] - compile 'io.ably:ably-android:1.2.0' + dependencies { + implementation 'io.ably:ably-android:1.2.0' + } + + repositories { + mavenCentral() + } ``` *Note*: In the above examples a specific version of the SDK is referenced. Ably recommends that you always use the latest stable version available for "Java":https://bintray.com/ably-io/ably/ably-java and "Android":https://bintray.com/ably-io/ably/ably-android. @@ -211,10 +223,10 @@ ably.connection.on('connected', function() { bc[java]. ClientOptions options = new ClientOptions("{{API_KEY}}"); AblyRealtime ably = new AblyRealtime(options); -ably.connection.on(ConnectionState.connected, new ConnectionStateListener() +ably.connection.on(ConnectionState.connected, new ConnectionStateListener() { @Override public void onConnectionStateChanged(ConnectionStateChange state) { - System.out.println("New state is " + change.current.name()); + System.out.println("New state is " + state.current.name()); switch (state.current) { case connected: { // Successful connection @@ -303,13 +315,12 @@ blang[python,php]. ```[java] Channel channel = ably.channels.get("quickstart"); - channel.subscribe(new MessageListener() { + channel.subscribe("greeting", new Channel.MessageListener() { @Override public void onMessage(Message message) { System.out.println("Received a greeting message in realtime: " + message.data); } }); - channel.publish("example", "message data"); ``` bc[swift]. let channel = ably.channels.get("quickstart") @@ -343,8 +354,11 @@ The following example code publishes a message to the @quickstart@ channel with bc[jsall](code-editor:quick-start-guide/send-message). var channel = ably.channels.get('quickstart'); channel.publish('greeting', 'hello!'); -bc[java]. Channel channel = ably.channels.get('quickstart'); -channel.publish('greeting', 'hello!'); +bc[java]. Channel channel = ably.channels.get("quickstart"); +channel.publish("greeting", "hello", new CompletionListener() { + @Override + public void onSuccess() { + System.out.println("Message sent"); bc[csharp]. var channel = ably.Channels.Get("quickstart"); channel.Publish("greeting", "hello!"); @@ -399,10 +413,10 @@ ably.connection.on('closed', function() { }); bc[java]. ably.connection.close(); -ably.connection.on(ConnectionState.closed, new ConnectionStateListener() +ably.connection.on(ConnectionState.closed, new ConnectionStateListener() { @Override public void onConnectionStateChanged(ConnectionStateChange state) { - System.out.println("New state is " + change.current.name()); + System.out.println("New state is " + state.current.name()); switch (state.current) { case closed: { // Connection closed From 40ae65d069c6c95ab1dcd6863b6e20908f044b15 Mon Sep 17 00:00:00 2001 From: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> Date: Fri, 13 Aug 2021 13:19:16 +0100 Subject: [PATCH 2/2] Fix alignment and add missing error handling --- content/root/quick-start-guide.textile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/content/root/quick-start-guide.textile b/content/root/quick-start-guide.textile index c8af50ef5b..ce3f8abf11 100644 --- a/content/root/quick-start-guide.textile +++ b/content/root/quick-start-guide.textile @@ -105,7 +105,7 @@ blang[java]. } repositories { - mavenCentral() + mavenCentral() } ``` @@ -117,7 +117,7 @@ blang[java]. } repositories { - mavenCentral() + mavenCentral() } ``` @@ -359,6 +359,12 @@ channel.publish("greeting", "hello", new CompletionListener() { @Override public void onSuccess() { System.out.println("Message sent"); + } + @Override + public void onError(ErrorInfo reason) { + System.out.println("Message not sent, error occurred: " + reason.message); + } +}); bc[csharp]. var channel = ably.Channels.Get("quickstart"); channel.Publish("greeting", "hello!");