All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.majusko.pulsar2.solon.consumer.DefaultConsumerInterceptor Maven / Gradle / Ivy

The newest version!
package io.github.majusko.pulsar2.solon.consumer;

import java.util.Set;

import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.ConsumerInterceptor;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.MessageId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultConsumerInterceptor implements ConsumerInterceptor {

    private final static Logger logger = LoggerFactory.getLogger(DefaultConsumerInterceptor.class);

    @Override
    public void close() {
        logger.debug("DefaultConsumerInterceptor closed");
    }

    @Override
    public Message beforeConsume(Consumer consumer, Message message) {
        logger.debug("[Pulsar consumer log:BeforeConsume] ProducerName[{}], ConsumerName:[{}], Topic:[{}], msgID:[{}]," +
                        " MessageKey:[{}], PublishTime:[{}], RedeliveryCount:[{}], GetReplicatedFrom:[{}]",
                message.getProducerName(), consumer.getConsumerName(), message.getTopicName(), message.getMessageId(),
                message.getKey(), message.getPublishTime(), message.getRedeliveryCount(), message.getReplicatedFrom());

        return message;
    }

    @Override
    public void onAcknowledge(Consumer consumer, MessageId messageId, Throwable exception) {
        if (exception != null) {
            logger.debug("[Pulsar consumer log:OnAcknowledge] ConsumerName:[{}], msgID:[{}], exception:[{}]", consumer.getConsumerName(), messageId, exception);
            return;
        }
        logger.debug("[Pulsar consumer log:OnAcknowledge] ConsumerName:[{}], msgID:[{}]", consumer.getConsumerName(), messageId);
    }

    @Override
    public void onAcknowledgeCumulative(Consumer consumer, MessageId messageId, Throwable exception) {
        if (exception != null) {
            logger.debug("[Pulsar consumer log:OnAcknowledgeCumulative] ConsumerName:[{}], msgID:[{}], exception:[{}]", consumer.getConsumerName(), messageId, exception);
            return;
        }
        logger.debug("[Pulsar consumer log:OnAcknowledgeCumulative] ConsumerName:[{}], msgID:[{}]", consumer.getConsumerName(), messageId);
    }

    @Override
    public void onNegativeAcksSend(Consumer consumer, Set messageIds) {
        logger.debug("[Pulsar consumer log:OnNegativeAcksSend] ConsumerName:[{}], msgID:[{}]", consumer.getConsumerName(), messageIds);
    }

    @Override
    public void onAckTimeoutSend(Consumer consumer, Set messageIds) {
        logger.debug("[Pulsar consumer log:OnAckTimeoutSend] ConsumerName:[{}], msgID:[{}]", consumer.getConsumerName(), messageIds);
    }

    @Override
    public void onPartitionsChange(String topicName, int partitions) {
        logger.debug("[Pulsar consumer log:OnPartitionsChange] Topic:[{}], Partitions:[{}]", topicName, partitions);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy