Available as of Camel 2.10
The websocket component provides websocket endpoints for communicating with clients using websocket. The component uses Eclipse Jetty Server which implements the IETF specification (drafts and RFC 6455). It supports the protocols ws:// and wss://. To use wss:// protocol, the SSLContextParameters must be defined.
Version currently supported
As Camel 2.10 uses Jetty 7.5.4.v20111024, only the D00 to D13 IETF implementations are available.
Camel 2.11 uses Jetty 7.6.7.
You can append query options to the URI in the following format,
WebsocketComponent can be configured prior to use, to setup host, to act as a websocket server.
The port number.
Path for static resources such as index.html files etc. If this option has been configured, then a server is started on the given hostname and port, to service the static resources, eg such as an index.html file. If this option has not been configured, then no server is started.
Reference to a
If this option is true, Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.
Consumer only: The password for the keystore when using SSL.
Consumer only: The password when using SSL.
Consumer only: The path to the keystore.
Consumer only: To set a value for minimum number of threads in server thread pool. From Camel 2.18: MinThreads/MaxThreads or threadPool fields are required due to switch to Jetty 9
Consumer only: To set a value for maximum number of threads in server thread pool. From Camel 2.18: MinThreads/MaxThreads or threadPool fields are required due to switch to Jetty 9
Consumer only: To use a custom thread pool for the server. From Camel 2.18: MinThreads/MaxThreads or threadPool fields are required due to switch to Jetty 9
WebsocketEndpoint can be configured prior to use
Deprecated and will be removed in Camel 3.0: Reference to a
Camel 2.11.1: Reference to a
Producer only: To send to all websocket subscribers. Can be used to configure on endpoint level, instead of having to use the
The root directory for the web resources or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath.
Camel 2.12.3: set the buffer size of the websocketServlet, which is also the max frame byte size (default 8192)
Camel 2.12.3: set the time in ms that the websocket created by the websocketServlet may be idle before closing. (default is 300000)
Camel 2.12.3: can be used to set the size in characters that the websocket created by the websocketServlet may be accept before closing.
Camel 2.12.3: can be used to set the size in bytes that the websocket created by the websocketServlet may be accept before closing. (Default is -1 - or unlimited)
Camel 2.12.3: can be used to set the minimum protocol version accepted for the websocketServlet. (Default 13 - the RFC6455 version)
|sendTimeout||30000||Camel 2.18: Timeout in millis when sending to a websocket channel. The default timeout is 30000 (30 seconds).|
The websocket component uses 2 headers to indicate to either send messages back to a single/current client, or to all clients.
Sends the message to all clients which are currently connected. You can use the
Sends the message to the client with the given connection key.
In this example we let Camel exposes a websocket server which clients can communicate with. The websocket server uses the default host and port, which would be
The example will send back an echo of the input. To send back a message, we need to send the transformed message to the same endpoint
"websocket://echo". This is needed
because by default the messaging is InOnly.
Here is another example where webapp resources location have been defined to allow the Jetty Application Server to not only register the WebSocket servlet but also to expose web resources for the browser. Resources should be defined under the webapp directory.
Setting up SSL for WebSocket Component
Using the JSSE Configuration Utility
As of Camel 2.10, the WebSocket component supports SSL/TLS configuration through the Camel JSSE Configuration Utility. This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels. The following examples demonstrate how to use the utility with the Cometd component.