protected PublisherPool createPublisherPool(final ProcessContext context) { final int maxMessageSize = context.getProperty(MAX_REQUEST_SIZE).asDataSize(DataUnit.B).intValue(); final long maxAckWaitMillis = context.getProperty(ACK_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS).longValue(); final Map<String, Object> kafkaProperties = new HashMap<>(); KafkaProcessorUtils.buildCommonKafkaProperties(context, ProducerConfig.class, kafkaProperties); kafkaProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put("max.request.size", String.valueOf(maxMessageSize)); return new PublisherPool(kafkaProperties, getLogger(), maxMessageSize, maxAckWaitMillis); }
@OnStopped public void closePool() { if (publisherPool != null) { publisherPool.close(); } publisherPool = null; }
public PublisherLease obtainPublisher() { if (isClosed()) { throw new IllegalStateException("Connection Pool is closed"); } PublisherLease lease = publisherQueue.poll(); if (lease != null) { return lease; } lease = createLease(); return lease; }
try (final PublisherLease lease = pool.obtainPublisher()) { if (useTransactions) { lease.beginTransaction();
@Override public void close() { if (isPoisoned() || isClosed()) { super.close(); } else { publisherQueue.offer(this); } } };
try (final PublisherLease lease = pool.obtainPublisher()) { if (useTransactions) { lease.beginTransaction();
@Override public void close() { if (isPoisoned() || isClosed()) { super.close(); } else { publisherQueue.offer(this); } } };
public PublisherLease obtainPublisher() { if (isClosed()) { throw new IllegalStateException("Connection Pool is closed"); } PublisherLease lease = publisherQueue.poll(); if (lease != null) { return lease; } lease = createLease(); return lease; }
@OnStopped public void closePool() { if (publisherPool != null) { publisherPool.close(); } publisherPool = null; }
protected PublisherPool createPublisherPool(final ProcessContext context) { final int maxMessageSize = context.getProperty(MAX_REQUEST_SIZE).asDataSize(DataUnit.B).intValue(); final long maxAckWaitMillis = context.getProperty(ACK_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS).longValue(); final Map<String, Object> kafkaProperties = new HashMap<>(); KafkaProcessorUtils.buildCommonKafkaProperties(context, ProducerConfig.class, kafkaProperties); kafkaProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put("max.request.size", String.valueOf(maxMessageSize)); return new PublisherPool(kafkaProperties, getLogger(), maxMessageSize, maxAckWaitMillis); }
try (final PublisherLease lease = pool.obtainPublisher()) { if (useTransactions) { lease.beginTransaction();
@Override public void close() { if (isPoisoned() || isClosed()) { super.close(); } else { publisherQueue.offer(this); } } };
public PublisherLease obtainPublisher() { if (isClosed()) { throw new IllegalStateException("Connection Pool is closed"); } PublisherLease lease = publisherQueue.poll(); if (lease != null) { return lease; } lease = createLease(); return lease; }
@OnStopped public void closePool() { if (publisherPool != null) { publisherPool.close(); } publisherPool = null; }
protected PublisherPool createPublisherPool(final ProcessContext context) { final int maxMessageSize = context.getProperty(MAX_REQUEST_SIZE).asDataSize(DataUnit.B).intValue(); final long maxAckWaitMillis = context.getProperty(ACK_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS).longValue(); final Map<String, Object> kafkaProperties = new HashMap<>(); KafkaProcessorUtils.buildCommonKafkaProperties(context, ProducerConfig.class, kafkaProperties); kafkaProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put("max.request.size", String.valueOf(maxMessageSize)); return new PublisherPool(kafkaProperties, getLogger(), maxMessageSize, maxAckWaitMillis); }
try (final PublisherLease lease = pool.obtainPublisher()) { if (useTransactions) { lease.beginTransaction();
@Override public void close() { if (isPoisoned() || isClosed()) { super.close(); } else { publisherQueue.offer(this); } } };
public PublisherLease obtainPublisher() { if (isClosed()) { throw new IllegalStateException("Connection Pool is closed"); } PublisherLease lease = publisherQueue.poll(); if (lease != null) { return lease; } lease = createLease(); return lease; }
@OnStopped public void closePool() { if (publisherPool != null) { publisherPool.close(); } publisherPool = null; }
protected PublisherPool createPublisherPool(final ProcessContext context) { final int maxMessageSize = context.getProperty(MAX_REQUEST_SIZE).asDataSize(DataUnit.B).intValue(); final long maxAckWaitMillis = context.getProperty(ACK_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS).longValue(); final String attributeNameRegex = context.getProperty(ATTRIBUTE_NAME_REGEX).getValue(); final Pattern attributeNamePattern = attributeNameRegex == null ? null : Pattern.compile(attributeNameRegex); final boolean useTransactions = context.getProperty(USE_TRANSACTIONS).asBoolean(); final String charsetName = context.getProperty(MESSAGE_HEADER_ENCODING).evaluateAttributeExpressions().getValue(); final Charset charset = Charset.forName(charsetName); final Map<String, Object> kafkaProperties = new HashMap<>(); KafkaProcessorUtils.buildCommonKafkaProperties(context, ProducerConfig.class, kafkaProperties); kafkaProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); kafkaProperties.put("max.request.size", String.valueOf(maxMessageSize)); return new PublisherPool(kafkaProperties, getLogger(), maxMessageSize, maxAckWaitMillis, useTransactions, attributeNamePattern, charset); }