Skip to content

Commit

Permalink
Step 4 – Publishing a message
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr.kazmierczak committed Dec 2, 2016
1 parent a0c24c5 commit 71f8444
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/io/ably/tutorial/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import io.ably.lib.realtime.AblyRealtime;
import io.ably.lib.realtime.Channel;
import io.ably.lib.realtime.CompletionListener;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.Message;

public class Example {
Expand Down Expand Up @@ -36,5 +38,19 @@ public void onMessage(Message messages) {
System.out.println("Message received: " + messages.data);
}
});

channel.publish("update", "new message", new CompletionListener() {
@Override
public void onSuccess() {
/* Show success message when message is sent */
System.out.println("Message sent");
}

@Override
public void onError(ErrorInfo reason) {
/* Show error message when something goes wrong */
System.out.println("Message not sent, error occurred: " + reason.message);
}
});
}
}

0 comments on commit 71f8444

Please sign in to comment.