Search in sources :

Example 1 with BaseCommand

use of org.apache.pulsar.common.api.proto.BaseCommand in project pulsar by apache.

the class ServerCnx method newMessageAndIntercept.

public ByteBufPair newMessageAndIntercept(long consumerId, long ledgerId, long entryId, int partition, int redeliveryCount, ByteBuf metadataAndPayload, long[] ackSet, String topic, long epoch) {
    BaseCommand command = Commands.newMessageCommand(consumerId, ledgerId, entryId, partition, redeliveryCount, ackSet, epoch);
    ByteBufPair res = Commands.serializeCommandMessageWithSize(command, metadataAndPayload);
    try {
        val brokerInterceptor = getBrokerService().getInterceptor();
        if (brokerInterceptor != null) {
            brokerInterceptor.onPulsarCommand(command, this);
            CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
            if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
                Consumer consumer = consumerFuture.getNow(null);
                brokerInterceptor.messageDispatched(this, consumer, ledgerId, entryId, metadataAndPayload);
            }
        } else {
            log.debug("BrokerInterceptor is not set in newMessageAndIntercept");
        }
    } catch (Exception e) {
        log.error("Exception occur when intercept messages.", e);
    }
    return res;
}
Also used : lombok.val(lombok.val) CommandCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ByteBufPair(org.apache.pulsar.common.protocol.ByteBufPair) ServiceUnitNotReadyException(org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) RestException(org.apache.pulsar.broker.web.RestException) InterceptException(org.apache.pulsar.common.intercept.InterceptException) TopicNotFoundException(org.apache.pulsar.broker.service.BrokerServiceException.TopicNotFoundException) ServerMetadataException(org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException) AuthenticationException(javax.naming.AuthenticationException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) SubscriptionNotFoundException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) CoordinatorException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException) NoSuchElementException(java.util.NoSuchElementException) ConsumerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)

Example 2 with BaseCommand

use of org.apache.pulsar.common.api.proto.BaseCommand in project pulsar by apache.

the class PulsarCommandSenderImpl method sendSendReceiptResponse.

@Override
public void sendSendReceiptResponse(long producerId, long sequenceId, long highestId, long ledgerId, long entryId) {
    BaseCommand command = Commands.newSendReceiptCommand(producerId, sequenceId, highestId, ledgerId, entryId);
    safeIntercept(command, cnx);
    ByteBuf outBuf = Commands.serializeWithSize(command);
    cnx.ctx().writeAndFlush(outBuf);
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with BaseCommand

use of org.apache.pulsar.common.api.proto.BaseCommand in project pulsar by apache.

the class PulsarCommandSenderImpl method sendGetOrCreateSchemaErrorResponse.

@Override
public void sendGetOrCreateSchemaErrorResponse(long requestId, ServerError error, String errorMessage) {
    BaseCommand command = Commands.newGetOrCreateSchemaResponseErrorCommand(requestId, error, errorMessage);
    safeIntercept(command, cnx);
    ByteBuf outBuf = Commands.serializeWithSize(command);
    cnx.ctx().writeAndFlush(outBuf);
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with BaseCommand

use of org.apache.pulsar.common.api.proto.BaseCommand in project pulsar by apache.

the class PulsarCommandSenderImpl method sendProducerSuccessResponse.

@Override
public void sendProducerSuccessResponse(long requestId, String producerName, long lastSequenceId, SchemaVersion schemaVersion, Optional<Long> topicEpoch, boolean isProducerReady) {
    BaseCommand command = Commands.newProducerSuccessCommand(requestId, producerName, lastSequenceId, schemaVersion, topicEpoch, isProducerReady);
    safeIntercept(command, cnx);
    ByteBuf outBuf = Commands.serializeWithSize(command);
    cnx.ctx().writeAndFlush(outBuf);
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with BaseCommand

use of org.apache.pulsar.common.api.proto.BaseCommand in project pulsar by apache.

the class PulsarCommandSenderImpl method sendPartitionMetadataResponse.

@Override
public void sendPartitionMetadataResponse(ServerError error, String errorMsg, long requestId) {
    BaseCommand command = Commands.newPartitionMetadataResponseCommand(error, errorMsg, requestId);
    safeIntercept(command, cnx);
    ByteBuf outBuf = Commands.serializeWithSize(command);
    cnx.ctx().writeAndFlush(outBuf);
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

BaseCommand (org.apache.pulsar.common.api.proto.BaseCommand)284 ByteBuf (io.netty.buffer.ByteBuf)68 MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)12 CommandAck (org.apache.pulsar.common.api.proto.CommandAck)9 CommandGetSchema (org.apache.pulsar.common.api.proto.CommandGetSchema)9 PulsarService (org.apache.pulsar.broker.PulsarService)6 CommandConnect (org.apache.pulsar.common.api.proto.CommandConnect)6 CommandLookupTopicResponse (org.apache.pulsar.common.api.proto.CommandLookupTopicResponse)6 Schema (org.apache.pulsar.common.api.proto.Schema)6 BeforeMethod (org.testng.annotations.BeforeMethod)4 NoSuchElementException (java.util.NoSuchElementException)3 AuthenticationException (javax.naming.AuthenticationException)3 lombok.val (lombok.val)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 ConsumerBusyException (org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)3 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)3 ServiceUnitNotReadyException (org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)3 SubscriptionNotFoundException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException)3 TopicNotFoundException (org.apache.pulsar.broker.service.BrokerServiceException.TopicNotFoundException)3 IncompatibleSchemaException (org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException)3