Java Code Examples for org.apache.pulsar.client.api.PulsarClientException#InvalidMessageException

The following examples show how to use org.apache.pulsar.client.api.PulsarClientException#InvalidMessageException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerImplTest.java    From pulsar with Apache License 2.0 8 votes vote down vote up
@Test(invocationTimeOut = 1000)
public void testNotifyPendingReceivedCallback_CompleteWithException() {
    CompletableFuture<Message<ConsumerImpl>> receiveFuture = new CompletableFuture<>();
    consumer.pendingReceives.add(receiveFuture);
    Exception exception = new PulsarClientException.InvalidMessageException("some random exception");
    consumer.notifyPendingReceivedCallback(null, exception);

    try {
        receiveFuture.join();
    } catch (CompletionException e) {
        // Completion exception must be the same we provided at calling time
        Assert.assertEquals(e.getCause(), exception);
    }

    Assert.assertTrue(receiveFuture.isCompletedExceptionally());
}
 
Example 2
Source File: PersistentReplicator.java    From pulsar with Apache License 2.0 7 votes vote down vote up
@Override
public void sendComplete(Exception exception) {
    if (exception != null && !(exception instanceof PulsarClientException.InvalidMessageException)) {
        log.error("[{}][{} -> {}] Error producing on remote broker", replicator.topicName,
                replicator.localCluster, replicator.remoteCluster, exception);
        // cursor should be rewinded since it was incremented when readMoreEntries
        replicator.cursor.rewind();
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[{}][{} -> {}] Message persisted on remote broker", replicator.topicName,
                    replicator.localCluster, replicator.remoteCluster);
        }
        replicator.cursor.asyncDelete(entry.getPosition(), replicator, entry.getPosition());
    }
    entry.release();

    int pending = PENDING_MESSAGES_UPDATER.decrementAndGet(replicator);

    // In general, we schedule a new batch read operation when the occupied queue size gets smaller than half
    // the max size, unless another read operation is already in progress.
    // If the producer is not currently writable (disconnected or TCP window full), we want to defer the reads
    // until we have emptied the whole queue, and at that point we will read a batch of 1 single message if the
    // producer is still not "writable".
    if (pending < replicator.producerQueueThreshold //
            && HAVE_PENDING_READ_UPDATER.get(replicator) == FALSE //
    ) {
        if (pending == 0 || replicator.producer.isWritable()) {
            replicator.readMoreEntries();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("[{}][{} -> {}] Not resuming reads. pending: {} is-writable: {}",
                        replicator.topicName, replicator.localCluster, replicator.remoteCluster, pending,
                        replicator.producer.isWritable());
            }
        }
    }

    recycle();
}
 
Example 3
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 7 votes vote down vote up
@Override
public void acknowledge(Message<?> message) throws PulsarClientException {
    try {
        acknowledge(message.getMessageId());
    } catch (NullPointerException npe) {
        throw new PulsarClientException.InvalidMessageException(npe.getMessage());
    }
}
 
Example 4
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 7 votes vote down vote up
@Override
public void acknowledgeCumulative(Message<?> message) throws PulsarClientException {
    try {
        acknowledgeCumulative(message.getMessageId());
    } catch (NullPointerException npe) {
        throw new PulsarClientException.InvalidMessageException(npe.getMessage());
    }
}
 
Example 5
Source File: V1_ProducerConsumerTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendBigMessageSize() throws Exception {
    log.info("-- Starting {} test --", methodName);

    final String topic = "persistent://my-property/use/my-ns/bigMsg";
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topic).create();

    // Messages are allowed up to MaxMessageSize
    producer.newMessage().value(new byte[Commands.DEFAULT_MAX_MESSAGE_SIZE]);

    try {
        producer.send(new byte[Commands.DEFAULT_MAX_MESSAGE_SIZE + 1]);
        fail("Should have thrown exception");
    } catch (PulsarClientException.InvalidMessageException e) {
        // OK
    }
}