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

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

commit 3bc50bbf74a1e153c1caff9f56ba36a43030c43e
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Oct 10 14:48:31 2024 +0200

    CAMEL-21193: camel-jbang - Add listen command
---
 .../modules/ROOT/pages/camel-jbang.adoc            | 65 +++++++++++++++++++++-
 .../dsl/jbang/core/commands/CamelJBangMain.java    |  2 +-
 .../core/commands/action/CamelReceiveAction.java   | 11 ++++
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index ea752eeb077..f25867ed324 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -1399,11 +1399,74 @@ For example to poll a message from a ActiveMQ queue 
named cheese you can do:
 
 [source,bash]
 ----
-$ camel cmd send --poll --endpoint=activemq:cheese
+$ camel cmd send --poll --endpoint='activemq:cheese'
 ----
 
 When you poll then you do not send any payload (body or headers).
 
+=== Receiving messages via Camel
+
+*Available since Camel 4.9*
+
+When building a prototype integration with Camel JBang, you may route messages 
to external systems.
+To know whether messages are being routed correctly, you may use system 
consoles to look inside these systems
+which messages have arrived, such as SQL prompts, web consoles, CLI tools etc.
+
+The Camel JBang now comes with a new command to receive messages from remote 
endpoints.
+This can be used to quickly look or tail in terminal the messages that an 
external systems has received.
+Camel does this by consuming the messages (if the component has support for 
consumer) and then let Camel JBang dump the messages from the CLI.
+
+For example to start dumping all messages from ActiveMQ in one command, you 
can do:
+
+[source,bash]
+----
+$ camel cmd receive --endpoint='activemq:cheese'
+----
+
+You can also use pattern syntax for the endpoint, so suppose you have the 
following route:
+
+[source,java]
+----
+from("ftp:myserver:1234/foo")
+  .to("log:order")
+  .to("activemq:orders");
+----
+
+Then you can tell Camel to automatic start receiving messages with:
+
+[source,bash]
+----
+$ camel cmd receive --action=start
+----
+
+TIP: You can enable and disable this mode with `--action=start` and 
`--action-stop`.
+
+Then Camel will automatically discover from the running integration, all the 
_producers_ and
+find the first _producer_ that is remote and also has consumer support. In the 
example above,
+that is the `activemq` component, and thus Camel will start receive from 
`activemq:orders`.
+
+You can see the status via:
+
+[source,bash]
+----
+$ camel cmd receive
+ PID   NAME   AGE   STATUS    TOTAL  SINCE  ENDPOINT
+  4364  foo   1m33s  Enabled     18     2s  activemq://orders
+----
+
+You can then dump all the received messages with:
+
+[source,bash]
+----
+$ camel cmd receive --action=dump
+----
+
+This will dump all the messages, and continue to dump new incoming messages. 
Use (ctrl + c) to break and exit.
+You can turn follow off with `--follow=false`.
+
+TIP: Use `camel cmd receive --help` to see all the various options for this 
command.
+
+
 === Controlling local Camel integrations
 
 To list the currently running Camel integrations, you use the `ps` command:
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index 7bf78415b32..2dd90261654 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -122,8 +122,8 @@ public class CamelJBangMain implements Callable<Integer> {
                         .addSubcommand("reset-stats", new CommandLine(new 
CamelResetStatsAction(main)))
                         .addSubcommand("reload", new CommandLine(new 
CamelReloadAction(main)))
                         .addSubcommand("send", new CommandLine(new 
CamelSendAction(main)))
+                        .addSubcommand("receive", new CommandLine(new 
CamelReceiveAction(main)))
                         .addSubcommand("browse", new CommandLine(new 
CamelBrowseAction(main)))
-                        .addSubcommand("listen", new CommandLine(new 
CamelReceiveAction(main)))
                         .addSubcommand("stub", new CommandLine(new 
CamelStubAction(main)))
                         .addSubcommand("thread-dump", new CommandLine(new 
CamelThreadDump(main)))
                         .addSubcommand("logger", new CommandLine(new 
LoggerAction(main)))
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 8aa46a3124d..055b140e8bb 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
@@ -172,6 +172,13 @@ public class CamelReceiveAction extends ActionBaseCommand {
 
     @Override
     public Integer doCall() throws Exception {
+        boolean autoDump = false;
+        if (endpoint != null) {
+            // if using --endpoint then action should be start and auto-dump
+            action = "start";
+            autoDump = true;
+        }
+
         if ("dump".equals(action)) {
             return doDumpCall();
         } else if ("status".equals(action)) {
@@ -231,6 +238,10 @@ public class CamelReceiveAction extends ActionBaseCommand {
             }
         }
 
+        if (autoDump) {
+            return doDumpCall();
+        }
+
         return 0;
     }
 

Reply via email to