Search code examples
sshapache-camelpolling

Apache Camel Non Polling SSH?


I'm trying to ssh to a server using camel-ssh component. When sshing to the server from the terminal (without command) the server starts to spit out data at regular intervals on new lines indefinitely i.e.

machine user$ ssh [email protected]
You are now master for the port.
 Escape Sequence is: Control-]

DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
DATA7
DATA8
DATA9
...

My application connects over serial but I never receive an exchange from the serial connection. After debugging for a bit it seems like the ssh-component expects to connect, send a command, await for the ssh session to close, send anything received during this time to an exchange and repeat.

In my use scenario, i'm not trying to send a command, so the ssh session never terminates. What I want to do is open a long running ssh session and get hold of each data packet sent during this time.

Is this possible with camel ssh?

Example camel route:

from("ssh://[email protected]:9001?pollCommand=%0A")
        .process(exchange -> {
            System.out.println(exchange.getIn().getBody(String.class));
        });

Solution

  • No this is not possible with camel-ssh. It is not what it was designed for (long poll), but as you can see, to run a single command and grab its output.

    You would need to build your own SSH code, or peak at the camel-ssh code and copy what you can use. And then need to figure out when a "data packet" ends (maybe a new line char) or something and then emit that as an event driven fashion.