use of com.yahoo.pulsar.client.api.PulsarClientException in project pulsar by yahoo.
the class PartitionedConsumerImpl method internalReceiveAsync.
@Override
protected CompletableFuture<Message> internalReceiveAsync() {
CompletableFuture<Message> result = new CompletableFuture<Message>();
Message message;
try {
lock.writeLock().lock();
message = incomingMessages.poll(0, TimeUnit.SECONDS);
if (message == null) {
pendingReceives.add(result);
} else {
resumeReceivingFromPausedConsumersIfNeeded();
result.complete(message);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
result.completeExceptionally(new PulsarClientException(e));
} finally {
lock.writeLock().unlock();
}
return result;
}
use of com.yahoo.pulsar.client.api.PulsarClientException in project pulsar by yahoo.
the class PartitionedConsumerImpl method messageReceived.
void messageReceived(Message message) {
lock.readLock().lock();
try {
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Received message from partitioned-consumer {}", topic, subscription, message.getMessageId());
}
// if asyncReceive is waiting : return message to callback without adding to incomingMessages queue
if (!pendingReceives.isEmpty()) {
CompletableFuture<Message> receivedFuture = pendingReceives.poll();
listenerExecutor.execute(() -> receivedFuture.complete(message));
} else {
// Enqueue the message so that it can be retrieved when application calls receive()
// Waits for the queue to have space for the message
incomingMessages.put(message);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
lock.readLock().unlock();
}
if (listener != null) {
// Trigger the notification on the message listener in a separate thread to avoid blocking the networking
// thread while the message processing happens
listenerExecutor.execute(() -> {
Message msg;
try {
msg = internalReceive();
} catch (PulsarClientException e) {
log.warn("[{}] [{}] Failed to dequeue the message for listener", topic, subscription, e);
return;
}
try {
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Calling message listener for message {}", topic, subscription, message.getMessageId());
}
listener.received(PartitionedConsumerImpl.this, msg);
} catch (Throwable t) {
log.error("[{}][{}] Message listener error in processing message: {}", topic, subscription, message, t);
}
});
}
}
use of com.yahoo.pulsar.client.api.PulsarClientException in project pulsar by yahoo.
the class ProducerImpl method batchMessageAndSend.
// must acquire semaphore before enqueuing
private void batchMessageAndSend() {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] Batching the messages from the batch container with {} messages", topic, producerName, batchMessageContainer.numMessagesInBatch);
}
OpSendMsg op = null;
int numMessagesInBatch = 0;
try {
if (!batchMessageContainer.isEmpty()) {
numMessagesInBatch = batchMessageContainer.numMessagesInBatch;
ByteBuf compressedPayload = batchMessageContainer.getCompressedBatchMetadataAndPayload();
long sequenceId = batchMessageContainer.sequenceId;
ByteBuf cmd = sendMessage(producerId, sequenceId, batchMessageContainer.numMessagesInBatch, batchMessageContainer.setBatchAndBuild(), compressedPayload);
op = OpSendMsg.create(batchMessageContainer.messages, cmd, sequenceId, batchMessageContainer.firstCallback);
op.setNumMessagesInBatch(batchMessageContainer.numMessagesInBatch);
op.setBatchSizeByte(batchMessageContainer.currentBatchSizeBytes);
batchMessageContainer.clear();
pendingMessages.put(op);
if (isConnected()) {
// If we do have a connection, the message is sent immediately, otherwise we'll try again once a new
// connection is established
cmd.retain();
cnx().ctx().channel().eventLoop().execute(WriteInEventLoopCallback.create(this, cnx(), op));
stats.updateNumMsgsSent(numMessagesInBatch, op.batchSizeByte);
} else {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] Connection is not ready -- sequenceId {}", topic, producerName, sequenceId);
}
}
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
semaphore.release(numMessagesInBatch);
if (op != null) {
op.callback.sendComplete(new PulsarClientException(ie));
}
} catch (Throwable t) {
semaphore.release(numMessagesInBatch);
log.warn("[{}] [{}] error while closing out batch -- {}", topic, producerName, t);
if (op != null) {
op.callback.sendComplete(new PulsarClientException(t));
}
}
}
use of com.yahoo.pulsar.client.api.PulsarClientException in project pulsar by yahoo.
the class PulsarClientImpl method shutdown.
@Override
public void shutdown() throws PulsarClientException {
try {
if (httpClient != null) {
httpClient.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 com.yahoo.pulsar.client.api.PulsarClientException in project pulsar by yahoo.
the class PersistentTopicE2ETest method testSingleClientMultipleSubscriptions.
@Test
public void testSingleClientMultipleSubscriptions() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/topic6";
final String subName = "sub6";
ConsumerConfiguration conf = new ConsumerConfiguration();
conf.setSubscriptionType(SubscriptionType.Exclusive);
pulsarClient.subscribe(topicName, subName, conf);
pulsarClient.createProducer(topicName);
try {
pulsarClient.subscribe(topicName, subName, conf);
fail("Should have thrown an exception since one consumer is already connected");
} catch (PulsarClientException cce) {
Assert.assertTrue(cce.getMessage().contains("Exclusive consumer is already connected"));
}
}
Aggregations