Search in sources :

Example 1 with ConsumerAck

use of org.apache.pulsar.websocket.data.ConsumerAck in project incubator-pulsar by apache.

the class ConsumerHandler method onWebSocketText.

@Override
public void onWebSocketText(String message) {
    super.onWebSocketText(message);
    // We should have received an ack
    MessageId msgId;
    try {
        ConsumerAck ack = ObjectMapperFactory.getThreadLocal().readValue(message, ConsumerAck.class);
        msgId = MessageId.fromByteArray(Base64.getDecoder().decode(ack.messageId));
    } catch (IOException e) {
        log.warn("Failed to deserialize message id: {}", message, e);
        close(WebSocketError.FailedToDeserializeFromJSON);
        return;
    }
    consumer.acknowledgeAsync(msgId).thenAccept(consumer -> numMsgsAcked.increment());
    int pending = pendingMessages.getAndDecrement();
    if (pending >= maxPendingMessages) {
        // Resume delivery
        receiveMessage();
    }
}
Also used : IOException(java.io.IOException) ConsumerAck(org.apache.pulsar.websocket.data.ConsumerAck) MessageId(org.apache.pulsar.client.api.MessageId)

Aggregations

IOException (java.io.IOException)1 MessageId (org.apache.pulsar.client.api.MessageId)1 ConsumerAck (org.apache.pulsar.websocket.data.ConsumerAck)1