Cannot connect to websocket server using AHC-WS component in Apache Camel

698 views Asked by At

I'm using ACH-WS component in Apache Camel to connect to a websocket server using WSS (Slack's websocket server to be more precise). I have a route like this one:

from("ahc-wss://host")
  .log(...)
  .to(...)

When I init my app I see the following log:

Route: wss-inbound-event started and consuming from: Endpoint[ahc-wss://ms109.slack-msgs.com/websocket/....]

However it sounds like the connection to the server never happens. If I copy the URL string and use another websocket client it connects and immediately get some welcome messages. This is the proof that AHC-WS component never connected because the URL can only be used once according to Slack's documentation.

I wonder if I need to provide additional options to the component in order to work.

1

There are 1 answers

0
dgaviola On BEST ANSWER

Looking at the code of the component it seems like it expects that you send a message first as the connection is established at that time. If you just create the consumer it won't connect to the URL.

To solve my issue what I did was to add a ping message to the Slack API one the app is started. That makes the endpoint connect to the server and starts receiving events.