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);
}
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations