= CometD Component
:doctitle: CometD
:shortname: cometd
:artifactid: camel-cometd
:description: Offers publish/subscribe, peer-to-peer (via a server), and RPC style messaging using the CometD/Bayeux protocol.
:since: 2.0
:supportlevel: Stable
:tabs-sync-option:
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:camel-spring-boot-name: cometd

*Since Camel {since}*

*{component-header}*

The Cometd component is a transport mechanism for working with the
http://www.mortbay.org/jetty[jetty] implementation of the
http://docs.codehaus.org/display/JETTY/Cometd+%28aka+Bayeux%29[cometd/bayeux
protocol]. +
 Using this component in combination with the dojo toolkit library, it's
possible to push Camel messages directly into the browser using an AJAX-based mechanism.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cometd</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

== URI format

----------------------------------------
cometd://host:port/channelName[?options]
----------------------------------------

The *channelName* represents a topic that can be subscribed to by the
Camel endpoints.

------------------------------------------
cometd://localhost:8080/service/mychannel
cometds://localhost:8443/service/mychannel
------------------------------------------

where `cometds:` represents an SSL configured endpoint.



// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
include::partial$component-endpoint-headers.adoc[]
// component options: END

== Examples

Below, you can find some examples of how to pass the parameters.

For file, for webapp resources located in the Web Application directory --> `cometd://localhost:8080?resourceBase=file./webapp`.

For classpath, when, for example, the web resources are packaged inside the webapp folder --> `cometd://localhost:8080?resourceBase=classpath:webapp`

=== Authentication

You can configure custom `SecurityPolicy` and `Extension`'s to the
`CometdComponent` which allows you to use authentication as
http://cometd.org/documentation/howtos/authentication[documented here]

=== Setting up SSL for Cometd Component

==== Using the JSSE Configuration Utility

The Cometd component supports SSL/TLS configuration
through the xref:manual::camel-configuration-utilities.adoc[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. You need to configure SSL
on the CometdComponent.x


[tabs]
====
Java::
+
Programmatic configuration of the component:
+
[source,java]
----
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("/users/home/server/keystore.jks");
ksp.setPassword("keystorePassword");

KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword("keyPassword");

TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);

SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);
scp.setTrustManagers(tmp);

CometdComponent commetdComponent = getContext().getComponent("cometds", CometdComponent.class);
commetdComponent.setSslContextParameters(scp);
----

Spring XML::
+
[source,xml]
----
  <camel:sslContextParameters
      id="sslContextParameters">
    <camel:keyManagers
        keyPassword="keyPassword">
      <camel:keyStore
          resource="/users/home/server/keystore.jks"
          password="keystorePassword"/>
    </camel:keyManagers>
    <camel:trustManagers>
      <camel:keyStore
          resource="/users/home/server/keystore.jks"
          password="keystorePassword"/>
    </camel:keyManagers>
  </camel:sslContextParameters>
 
  <bean id="cometd" class="org.apache.camel.component.cometd.CometdComponent">
    <property name="sslContextParameters" ref="sslContextParameters"/>
  </bean>

  <to uri="cometds://127.0.0.1:443/service/test?baseResource=file:./target/test-classes/webapp&timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2"/>...
----

====


include::spring-boot:partial$starter.adoc[]
