PubSubMessageListener Class - Android
onMessageReceived()
-
This event will be emitted whenever any pubsub message received.
-
Parameter:
message— typePubSubMessage
onOldMessagesReceived()
-
This event will be emitted with one batch of the topic's persisted messages after subscribing.
-
Only messages published with
persistenabled are persisted; a topic with none fires no history callback at all. -
Parameter:
messages— typeList<PubSubMessage>
History is replayed in server-paced batches, so this is called once per batch with a partial list — append the messages to what you already hold rather than replacing it. This method carries no end-of-replay signal; override onOldMessagesReceived(messages, info) when you need to know that history is complete.
onOldMessagesReceived(messages, info)
-
This event will be emitted for each batch of the topic's persisted messages after subscribing.
-
History streams in server-paced batches; the final batch carries
info.isLast()astrue. -
Both
subscribe(topic, listener)and thePubSubSubscribeOptionsoverload replay history this way — the options change only how much of it is replayed, never how it is delivered. -
Parameters:
messages— typeList<PubSubMessage>, the historical messages in this batch.info— typePubSubHistoryInfo, batch metadata. See PubSubHistoryInfo.
-
If you do not override this method, the SDK forwards each batch to
onOldMessagesReceived(messages), so a listener written against that method receives every message without overriding this one.
A topic with no history fires no history callback at all. Do not wait on isLast() to detect an empty topic.
onBatchReceived()
-
This event will be emitted once per live batch with all messages of that batch, before the per-message
onMessageReceived()calls for the same batch. -
Override this to amortise per-message work — a single database transaction or analytics flush per batch instead of one per message.
-
Parameter:
messages— typeList<PubSubMessage>, the live messages in this batch.
Batched delivery is enabled per meeting by the server configuration, not by subscribe options. Where it is not enabled this method is never called and live messages arrive solely through onMessageReceived() — handle both paths. Because the callback runs on the main thread, move the work itself off it.
onMessageDrop()
-
This event will be emitted when live messages were dropped because the subscriber's buffer overflowed under
RealtimeOverflow.QUEUE. -
Parameter:
info— typePubSubMessageDropInfo. See PubSubMessageDropInfo. -
It is coalesced — it fires once per drop event, not once per dropped message, and never fires under
RealtimeOverflow.DROP.
Example
- Kotlin
- Java
val pubSubMessageListener = object : PubSubMessageListener {
override fun onMessageReceived(message: PubSubMessage) {
Log.d("#message", "onMessageReceived: ${message.message}")
}
override fun onOldMessagesReceived(messages: List<PubSubMessage>) {
Log.d("#message", "onOldMessagesReceived: $messages")
}
override fun onOldMessagesReceived(messages: List<PubSubMessage>, info: PubSubHistoryInfo) {
Log.d("#message", "history batch of ${messages.size}, isLast: ${info.isLast}")
}
override fun onBatchReceived(messages: List<PubSubMessage>) {
Log.d("#message", "onBatchReceived: ${messages.size} messages")
}
override fun onMessageDrop(info: PubSubMessageDropInfo) {
Log.d("#message", "onMessageDrop: ${info.droppedCount} messages lost")
}
}
PubSubMessageListener pubSubMessageListener = new PubSubMessageListener() {
@Override
public void onMessageReceived(PubSubMessage message) {
Log.d("#message", "onMessageReceived: " + message.getMessage());
}
@Override
public void onOldMessagesReceived(List<PubSubMessage> messages) {
Log.d("#message", "onOldMessagesReceived: " + messages);
}
@Override
public void onOldMessagesReceived(List<PubSubMessage> messages, PubSubHistoryInfo info) {
Log.d("#message", "history batch of " + messages.size() + ", isLast: " + info.isLast());
}
@Override
public void onBatchReceived(List<PubSubMessage> messages) {
Log.d("#message", "onBatchReceived: " + messages.size() + " messages");
}
@Override
public void onMessageDrop(PubSubMessageDropInfo info) {
Log.d("#message", "onMessageDrop: " + info.getDroppedCount() + " messages lost");
}
};
PubSubHistoryInfo
Metadata for a batch of historical messages delivered via onOldMessagesReceived(messages, info).
isLast()
-
type:
boolean -
Returns
trueon the final history batch, meaning the topic's history is complete.
PubSubMessageDropInfo
Details of a message-drop event delivered via onMessageDrop().
getDroppedCount()
-
type:
int -
Returns how many live messages were lost in this drop event. The event is coalesced, so one event can represent many dropped messages.
Got a Question? Ask us on discord

