이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 67. CometD Component


Available as of Camel version 2.0

The cometd: component is a transport for working with the jetty implementation of the 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:

<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>

67.1. URI format

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

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

67.2. Examples

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

where cometds: represents an SSL configured endpoint.

67.3. Options

The CometD component supports 8 options which are listed below.

NameDescriptionDefaultType

sslKeyPassword (security)

The password for the keystore when using SSL.

 

String

sslPassword (security)

The password when using SSL.

 

String

sslKeystore (security)

The path to the keystore.

 

String

securityPolicy (security)

To use a custom configured SecurityPolicy to control authorization

 

SecurityPolicy

extensions (common)

To use a list of custom BayeuxServer.Extension that allows modifying incoming and outgoing requests.

 

List

sslContextParameters (security)

To configure security using SSLContextParameters

 

SSLContextParameters

useGlobalSslContext Parameters (security)

Enable usage of global SSL context parameters.

false

boolean

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The CometD endpoint is configured using URI syntax:

cometd:host:port/channelName

with the following path and query parameters:

67.3.1. Path Parameters (3 parameters):

NameDescriptionDefaultType

host

Required Hostname

 

String

port

Required Host port number

 

int

channelName

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

 

String

67.3.2. Query Parameters (16 parameters):

NameDescriptionDefaultType

allowedOrigins (common)

The origins domain that support to cross, if the crosssOriginFilterOn is true

*

String

baseResource (common)

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. Classpath is required for OSGI deployment where the resources are packaged in the jar

 

String

crossOriginFilterOn (common)

If true, the server will support for cross-domain filtering

false

boolean

filterPath (common)

The filterPath will be used by the CrossOriginFilter, if the crosssOriginFilterOn is true

 

String

interval (common)

The client side poll timeout in milliseconds. How long a client will wait between reconnects

 

int

jsonCommented (common)

If true, the server will accept JSON wrapped in a comment and will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking.

true

boolean

logLevel (common)

Logging level. 0=none, 1=info, 2=debug.

1

int

maxInterval (common)

The max client side poll timeout in milliseconds. A client will be removed if a connection is not received in this time.

30000

int

multiFrameInterval (common)

The client side poll timeout, if multiple connections are detected from the same browser.

1500

int

timeout (common)

The server side poll timeout in milliseconds. This is how long the server will hold a reconnect request before responding.

240000

int

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

sessionHeadersEnabled (consumer)

Whether to include the server session headers in the Camel message when creating a Camel Message for incoming requests.

false

boolean

exceptionHandler (consumer)

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

disconnectLocalSession (producer)

Whether to disconnect local sessions after publishing a message to its channel. Disconnecting local session is needed as they are not swept by default by CometD, and therefore you can run out of memory.

false

boolean

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

You can append query options to the URI in the following format, ?option=value&option=value&…​

Here is some examples on 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 by example the web resources are packaged inside the webapp folder -→ cometd://localhost:8080?resourceBase=classpath:webapp

67.4. Authentication

Available as of Camel 2.8

You can configure custom SecurityPolicy and Extension’s to the `CometdComponent which allows you to use authentication as documented here

67.5. Setting up SSL for Cometd Component

67.5.1. Using the JSSE Configuration Utility

As of Camel 2.9, the Cometd 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. You need to configure SSL on the CometdComponent.

Programmatic configuration of the component

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 DSL based configuration of endpoint

...
  <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"/>...

67.6. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.