@Override public void close() throws Exception { producer.close(); }
@Override public void shutdown() { try { producer.close(); pulsarClient.close(); } catch (final Exception ex) { } }
@Override public void close() throws Exception { if (producer != null) { producer.close(); } // make sure we propagate pending errors checkErroneous(); }
@Override public void stop() { if (null != producer) { try { producer.close(); } catch (PulsarClientException e) { log.warn("Failed to close producer", e); } } if (null != reader) { try { reader.close(); } catch (IOException e) { log.warn("Failed to close reader", e); } } if (null != client) { try { client.close(); } catch (IOException e) { log.warn("Failed to close client", e); } } }
@SuppressWarnings("unchecked") public <O> CompletableFuture<Void> publish(String topicName, O object, Schema<O> schema) { Producer<O> producer = (Producer<O>) publishProducers.get(topicName); if (producer == null) { try { Producer<O> newProducer = ((ProducerBuilderImpl<O>) producerBuilder.clone()) .schema(schema).topic(topicName).create(); Producer<O> existingProducer = (Producer<O>) publishProducers.putIfAbsent(topicName, newProducer); if (existingProducer != null) { // The value in the map was not updated after the concurrent put newProducer.close(); producer = existingProducer; } else { producer = newProducer; } } catch (PulsarClientException e) { logger.error("Failed to create Producer while doing user publish", e); return FutureUtil.failedFuture(e); } } return producer.sendAsync(object).thenApply(msgId -> null); }