This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 14eb9a58043a CAMEL-22952: camel-jbang - Fix receive command to work 
better and auto select if only 1 camel app running.
14eb9a58043a is described below

commit 14eb9a58043ac059858c7c3103ff50a54314f539
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Feb 3 21:52:14 2026 +0100

    CAMEL-22952: camel-jbang - Fix receive command to work better and auto 
select if only 1 camel app running.
---
 .../core/commands/action/CamelReceiveAction.java   | 37 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
index 043f0766d00f..c9c8cd9d297f 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
@@ -227,8 +227,14 @@ public class CamelReceiveAction extends ActionBaseCommand {
         if (name != null) {
             return doCall(name, autoDump);
         } else {
-            return doCallLocal(autoDump);
+            // are there only 1 pid running then use that
+            List<Long> pids = findPids("*");
+            if (pids.size() == 1) {
+                return doCall(pids.get(0), autoDump);
+            }
         }
+        // okay fallback and run camel locally to connect to external system
+        return doCallLocal(autoDump);
     }
 
     private Integer doCall(String name, boolean autoDump) throws Exception {
@@ -240,7 +246,8 @@ public class CamelReceiveAction extends ActionBaseCommand {
                     Files.writeString(f, "{}");
                 }
             } else {
-                Path outputFile = writeReceiveData();
+                Path outputFile = writeReceiveData(pid);
+                printer().println("Starting to receive messages from existing 
Camel: " + name + " (pid: " + pid + ")");
                 showStatus(outputFile);
             }
         }
@@ -252,6 +259,26 @@ public class CamelReceiveAction extends ActionBaseCommand {
         return 0;
     }
 
+    private Integer doCall(long pid, boolean autoDump) throws Exception {
+        this.pid = pid;
+        if ("clear".equals(action)) {
+            Path f = getReceiveFile("" + pid);
+            if (Files.exists(f)) {
+                Files.writeString(f, "{}");
+            }
+        } else {
+            Path outputFile = writeReceiveData(pid);
+            printer().println("Starting to receive messages from existing 
Camel (pid: " + pid + ")");
+            showStatus(outputFile);
+        }
+
+        if (autoDump) {
+            return doDumpCall();
+        }
+
+        return 0;
+    }
+
     private Integer doCallLocal(boolean autoDump) throws Exception {
         AtomicReference<KameletMain> ref = new AtomicReference<>();
         Run run = new Run(this.getMain()) {
@@ -268,7 +295,7 @@ public class CamelReceiveAction extends ActionBaseCommand {
         // spawn thread that waits for response file
         final CountDownLatch latch = new CountDownLatch(1);
         this.pid = ProcessHandle.current().pid();
-        Path outputFile = writeReceiveData();
+        Path outputFile = writeReceiveData(this.pid);
         Thread t = new Thread("CamelJBangSendStatus") {
             @Override
             public void run() {
@@ -294,6 +321,8 @@ public class CamelReceiveAction extends ActionBaseCommand {
         };
         // keep thread running as we need it to show the status before 
terminating
         t.start();
+        printer().println(
+                "Starting to receive messages by connecting to external system 
using local process (pid: " + pid + ")");
 
         Integer exit = run.call();
         latch.await();
@@ -301,7 +330,7 @@ public class CamelReceiveAction extends ActionBaseCommand {
         return exit;
     }
 
-    protected Path writeReceiveData() {
+    protected Path writeReceiveData(long pid) {
         // ensure output file is deleted before executing action
         Path outputFile = getOutputFile(Long.toString(pid));
         PathUtils.deleteFile(outputFile);

Reply via email to