Search in sources :

Example 1 with ConsumerAck

use of com.yahoo.pulsar.websocket.data.ConsumerAck in project pulsar by yahoo.

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);
    int pending = pendingMessages.getAndDecrement();
    if (pending >= maxPendingMessages) {
        // Resume delivery
        receiveMessage();
    }
}
Also used : IOException(java.io.IOException) ConsumerAck(com.yahoo.pulsar.websocket.data.ConsumerAck) MessageId(com.yahoo.pulsar.client.api.MessageId)

Aggregations

MessageId (com.yahoo.pulsar.client.api.MessageId)1 ConsumerAck (com.yahoo.pulsar.websocket.data.ConsumerAck)1 IOException (java.io.IOException)1