Search in sources :

Example 21 with PulsarClientException

use of org.apache.pulsar.client.api.PulsarClientException in project incubator-pulsar by apache.

the class TopicsConsumerImpl method internalReceive.

@Override
protected Message<T> internalReceive() throws PulsarClientException {
    Message<T> message;
    try {
        message = incomingMessages.take();
        checkState(message instanceof TopicMessageImpl);
        unAckedMessageTracker.add(message.getMessageId());
        resumeReceivingFromPausedConsumersIfNeeded();
        return message;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new PulsarClientException(e);
    }
}
Also used : PulsarClientException(org.apache.pulsar.client.api.PulsarClientException)

Example 22 with PulsarClientException

use of org.apache.pulsar.client.api.PulsarClientException in project incubator-pulsar by apache.

the class PulsarClientImpl method shutdown.

@Override
public void shutdown() throws PulsarClientException {
    try {
        lookup.close();
        cnxPool.close();
        timer.stop();
        externalExecutorProvider.shutdownNow();
        conf.getAuthentication().close();
    } catch (Throwable t) {
        log.warn("Failed to shutdown Pulsar client", t);
        throw new PulsarClientException(t);
    }
}
Also used : PulsarClientException(org.apache.pulsar.client.api.PulsarClientException)

Example 23 with PulsarClientException

use of org.apache.pulsar.client.api.PulsarClientException in project incubator-pulsar by apache.

the class PulsarClientImpl method createProducer.

@Override
public Producer<byte[]> createProducer(final String topic, final ProducerConfiguration conf) throws PulsarClientException {
    if (conf == null) {
        throw new PulsarClientException.InvalidConfigurationException("Invalid null configuration object");
    }
    try {
        ProducerConfigurationData confData = conf.getProducerConfigurationData().clone();
        confData.setTopicName(topic);
        return createProducerAsync(confData).get();
    } catch (ExecutionException e) {
        Throwable t = e.getCause();
        if (t instanceof PulsarClientException) {
            throw (PulsarClientException) t;
        } else {
            throw new PulsarClientException(t);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new PulsarClientException(e);
    }
}
Also used : ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with PulsarClientException

use of org.apache.pulsar.client.api.PulsarClientException in project incubator-pulsar by apache.

the class ContinuousProducer method main.

public static void main(String[] args) throws PulsarClientException, InterruptedException, IOException {
    PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("http://127.0.0.1:8080").build();
    Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic").create();
    while (true) {
        try {
            producer.send("my-message".getBytes());
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
            break;
        }
    }
    pulsarClient.close();
}
Also used : PulsarClient(org.apache.pulsar.client.api.PulsarClient) IOException(java.io.IOException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException)

Example 25 with PulsarClientException

use of org.apache.pulsar.client.api.PulsarClientException in project incubator-pulsar by apache.

the class SampleConsumerListener method main.

public static void main(String[] args) throws PulsarClientException, InterruptedException, IOException {
    PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("http://localhost:8080").build();
    // 
    pulsarClient.newConsumer().topic(// 
    "persistent://my-property/use/my-ns/my-topic").subscriptionName(// 
    "my-subscription-name").messageListener((consumer, msg) -> {
        log.info("Received message: {}", msg);
        consumer.acknowledgeAsync(msg);
    }).subscribe();
    // Block main thread
    System.in.read();
    pulsarClient.close();
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) IOException(java.io.IOException) PulsarClient(org.apache.pulsar.client.api.PulsarClient) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) PulsarClient(org.apache.pulsar.client.api.PulsarClient)

Aggregations

PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)65 Test (org.testng.annotations.Test)24 CompletableFuture (java.util.concurrent.CompletableFuture)17 Message (org.apache.pulsar.client.api.Message)15 IOException (java.io.IOException)14 PulsarClient (org.apache.pulsar.client.api.PulsarClient)13 ExecutionException (java.util.concurrent.ExecutionException)12 Consumer (org.apache.pulsar.client.api.Consumer)12 MessageId (org.apache.pulsar.client.api.MessageId)12 Producer (org.apache.pulsar.client.api.Producer)12 ByteBuf (io.netty.buffer.ByteBuf)11 List (java.util.List)8 ConsumerConfiguration (org.apache.pulsar.client.api.ConsumerConfiguration)8 ProducerConfiguration (org.apache.pulsar.client.api.ProducerConfiguration)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 TimeUnit (java.util.concurrent.TimeUnit)5