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

The following examples show how to use org.apache.pulsar.client.api.PulsarClientException#TopicTerminatedException . 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: TopicTerminationTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTermination() throws Exception {
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
        .enableBatching(false)
        .messageRoutingMode(MessageRoutingMode.SinglePartition)
        .create();

    /* MessageId msgId1 = */producer.send("test-msg-1".getBytes());
    /* MessageId msgId2 = */producer.send("test-msg-2".getBytes());
    MessageId msgId3 = producer.send("test-msg-3".getBytes());

    MessageId lastMessageId = admin.topics().terminateTopicAsync(topicName).get();
    assertEquals(lastMessageId, msgId3);

    try {
        producer.send("test-msg-4".getBytes());
        fail("Should have thrown exception");
    } catch (PulsarClientException.TopicTerminatedException e) {
        // Expected
    }
}
 
Example 2
Source File: TopicTerminationTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateProducerOnTerminatedTopic() throws Exception {
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
        .enableBatching(false)
        .messageRoutingMode(MessageRoutingMode.SinglePartition)
        .create();

    /* MessageId msgId1 = */producer.send("test-msg-1".getBytes());
    /* MessageId msgId2 = */producer.send("test-msg-2".getBytes());
    MessageId msgId3 = producer.send("test-msg-3".getBytes());

    MessageId lastMessageId = admin.topics().terminateTopicAsync(topicName).get();
    assertEquals(lastMessageId, msgId3);

    try {
        pulsarClient.newProducer().topic(topicName).create();
        fail("Should have thrown exception");
    } catch (PulsarClientException.TopicTerminatedException e) {
        // Expected
    }
}
 
Example 3
Source File: ClientCnx.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private PulsarClientException getPulsarClientException(ServerError error, String errorMsg) {
    switch (error) {
    case AuthenticationError:
        return new PulsarClientException.AuthenticationException(errorMsg);
    case AuthorizationError:
        return new PulsarClientException.AuthorizationException(errorMsg);
    case ProducerBusy:
        return new PulsarClientException.ProducerBusyException(errorMsg);
    case ConsumerBusy:
        return new PulsarClientException.ConsumerBusyException(errorMsg);
    case MetadataError:
        return new PulsarClientException.BrokerMetadataException(errorMsg);
    case PersistenceError:
        return new PulsarClientException.BrokerPersistenceException(errorMsg);
    case ServiceNotReady:
        return new PulsarClientException.LookupException(errorMsg);
    case TooManyRequests:
        return new PulsarClientException.TooManyRequestsException(errorMsg);
    case ProducerBlockedQuotaExceededError:
        return new PulsarClientException.ProducerBlockedQuotaExceededError(errorMsg);
    case ProducerBlockedQuotaExceededException:
        return new PulsarClientException.ProducerBlockedQuotaExceededException(errorMsg);
    case TopicTerminatedError:
        return new PulsarClientException.TopicTerminatedException(errorMsg);
    case IncompatibleSchema:
        return new PulsarClientException.IncompatibleSchemaException(errorMsg);
    case TopicNotFound:
        return new PulsarClientException.TopicDoesNotExistException(errorMsg);
    case ConsumerAssignError:
        return new PulsarClientException.ConsumerAssignException(errorMsg);
    case UnknownError:
    default:
        return new PulsarClientException(errorMsg);
    }
}