Skip to content

Commit 098e674

Browse files
author
piotr.kazmierczak
committed
Step 4 – Publishing a message
1 parent 519d498 commit 098e674

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/io/ably/tutorial/Example.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import io.ably.lib.realtime.AblyRealtime;
44
import io.ably.lib.realtime.Channel;
5+
import io.ably.lib.realtime.CompletionListener;
56
import io.ably.lib.types.AblyException;
7+
import io.ably.lib.types.ErrorInfo;
68
import io.ably.lib.types.Message;
79

810
public class Example {
@@ -36,5 +38,19 @@ public void onMessage(Message messages) {
3638
System.out.println("Message received: " + messages.data);
3739
}
3840
});
41+
42+
channel.publish("update", "new message", new CompletionListener() {
43+
@Override
44+
public void onSuccess() {
45+
/* Show success message when message is sent */
46+
System.out.println("Message sent");
47+
}
48+
49+
@Override
50+
public void onError(ErrorInfo reason) {
51+
/* Show error message when something goes wrong */
52+
System.out.println("Message not sent, error occurred: " + reason.message);
53+
}
54+
});
3955
}
4056
}

0 commit comments

Comments
 (0)