You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2026/10/02 12:26:26 UTC
(streampipes) branch dev updated: fix: Close sample connection of NATS adapter after schema guess (#5065)
This is an automated email from the ASF dual-hosted git repository.
tenthe pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 7c6b29de4b fix: Close sample connection of NATS adapter after schema guess (#5065)
7c6b29de4b is described below
commit 7c6b29de4b1d44ce6e2614ded6eb70ebc28bfc8f
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Fri Oct 2 14:26:20 2026 +0200
fix: Close sample connection of NATS adapter after schema guess (#5065)
---
.../connectors/nats/adapter/NatsProtocol.java | 29 ++++++++++++++--------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/streampipes-extensions/streampipes-connectors-nats/src/main/java/org/apache/streampipes/extensions/connectors/nats/adapter/NatsProtocol.java b/streampipes-extensions/streampipes-connectors-nats/src/main/java/org/apache/streampipes/extensions/connectors/nats/adapter/NatsProtocol.java
index dbfe013ad9..da50d3907f 100644
--- a/streampipes-extensions/streampipes-connectors-nats/src/main/java/org/apache/streampipes/extensions/connectors/nats/adapter/NatsProtocol.java
+++ b/streampipes-extensions/streampipes-connectors-nats/src/main/java/org/apache/streampipes/extensions/connectors/nats/adapter/NatsProtocol.java
@@ -165,27 +165,34 @@ public class NatsProtocol implements StreamPipesAdapter {
) throws AdapterException {
this.applyConfiguration(extractor.getStaticPropertyExtractor());
List<byte[]> elements = new ArrayList<>();
- this.natsConsumer = new NatsConsumer(natsConfig);
+ var sampleConsumer = new NatsConsumer(natsConfig);
final boolean[] completed = {false};
InternalEventProcessor<byte[]> processor = event -> {
- elements.add(event);
- completed[0] = true;
+ if (!completed[0]) {
+ elements.add(event);
+ completed[0] = true;
+ }
};
try {
- this.natsConsumer.connect(processor);
+ sampleConsumer.connect(processor);
} catch (SpRuntimeException e) {
throw new ParseException("Could not connect to Nats broker", e);
}
- int totalTimeout = 0;
- while (!completed[0] && totalTimeout < MAX_TIMEOUT) {
- try {
- TimeUnit.MILLISECONDS.sleep(TIMEOUT);
- totalTimeout += TIMEOUT;
- } catch (InterruptedException e) {
- e.printStackTrace();
+ try {
+ int totalTimeout = 0;
+ while (!completed[0] && totalTimeout < MAX_TIMEOUT) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(TIMEOUT);
+ totalTimeout += TIMEOUT;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ } finally {
+ // The sample connection is only needed for the first event
+ sampleConsumer.disconnect();
}
if (elements.size() > 0) {
return extractor.selectedParser()