Webhook
Since Camel 3.0
Only consumer is supported
The Webhook meta-component allows other Camel components to configure webhooks on a remote webhook provider and listen for them.
Maven users can add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-webhook</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Typically, other components that support webhook will bring this dependency transitively.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Webhook component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. 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 | |
Whether the delegate component registers the URL of the webhook at the provider when the endpoint starts, and unregisters it when the endpoint stops, for example with the setWebhook and deleteWebhook calls of the Telegram Bot API. Set it to false when the webhook is registered in another way, for example with a WebhookRoutePolicyFactory, which requires false. The WhatsApp component does not register the webhook. | true | boolean | |
A path put in front of webhookPath in the path of the webhook, for example a random value that is hard to guess, so that only the provider knows the URL. A leading slash is added when missing. If not set, the path of the webhook is webhookPath alone. | String | ||
The name of the REST component that exposes the HTTP endpoint of the webhook, such as platform-http or netty-http. It names a bean in the registry or a component, which must be a RestConsumerFactory. If not set, a component of the CamelContext that is a RestConsumerFactory is used, otherwise the only RestConsumerFactory bean in the registry, otherwise the only one of coap, netty-http, jetty, servlet and undertow on the classpath. | String | ||
The URL at which the webhook provider reaches this service, for example https://camel.example.com, without a trailing slash. The delegate component registers this URL followed by the path of the webhook (the context path of the REST configuration, webhookBasePath and webhookPath) at the provider. If not set, the URL is made from the scheme, host and port of the REST configuration. When that has no host, its hostNameResolver picks one, which is 0.0.0.0 by default and which the provider cannot reach. | String | ||
The path of the webhook, after webhookBasePath. A leading slash is added when missing. If not set, the path is the SHA-256 hash of the delegate endpoint URI in URL-safe Base64, which stays the same across restarts. The WhatsApp component replaces it with its own webhookPath option. | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The default webhook options of the endpoints that the component creates. Each endpoint starts with a copy of it, which the options of the endpoint then change. | WebhookConfiguration |
Endpoint Options
The Webhook endpoint is configured using URI syntax:
webhook:endpointUri
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The URI of the delegate endpoint, of a component that supports webhooks, for example telegram:bots, clickup:workspaceId or whatsapp:phoneNumberId. The query parameters of the webhook endpoint that are not webhook options are passed on to the delegate endpoint. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether the delegate component registers the URL of the webhook at the provider when the endpoint starts, and unregisters it when the endpoint stops, for example with the setWebhook and deleteWebhook calls of the Telegram Bot API. Set it to false when the webhook is registered in another way, for example with a WebhookRoutePolicyFactory, which requires false. The WhatsApp component does not register the webhook. | true | boolean | |
A path put in front of webhookPath in the path of the webhook, for example a random value that is hard to guess, so that only the provider knows the URL. A leading slash is added when missing. If not set, the path of the webhook is webhookPath alone. | String | ||
The name of the REST component that exposes the HTTP endpoint of the webhook, such as platform-http or netty-http. It names a bean in the registry or a component, which must be a RestConsumerFactory. If not set, a component of the CamelContext that is a RestConsumerFactory is used, otherwise the only RestConsumerFactory bean in the registry, otherwise the only one of coap, netty-http, jetty, servlet and undertow on the classpath. | String | ||
The URL at which the webhook provider reaches this service, for example https://camel.example.com, without a trailing slash. The delegate component registers this URL followed by the path of the webhook (the context path of the REST configuration, webhookBasePath and webhookPath) at the provider. If not set, the URL is made from the scheme, host and port of the REST configuration. When that has no host, its hostNameResolver picks one, which is 0.0.0.0 by default and which the provider cannot reach. | String | ||
The path of the webhook, after webhookBasePath. A leading slash is added when missing. If not set, the path is the SHA-256 hash of the delegate endpoint URI in URL-safe Base64, which stays the same across restarts. The WhatsApp component replaces it with its own webhookPath option. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. 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 | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern |
Message Body
The message body at each side of the Webhook component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The body the webhook handler of the delegate component (endpointUri) makes of the HTTP request: the same body as its polling consumer, such as an IncomingMessage (or another update) for Telegram, an Event for ClickUp, or the JSON as a String for WhatsApp. |
Consumer reply |
| The delegate component sets the HTTP response body itself after the route: Telegram and ClickUp reply with an empty body, WhatsApp with the request content, whatever body the route ends with. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Put webhook: in front of the URI of a component that supports webhooks. The options that start with webhook are for this component, and the other options are for the delegate endpoint.
At startup, Camel exposes a REST endpoint for the webhook and registers its URL at the provider (webhookAutoRegister). The provider must reach that URL, so set webhookExternalUrl to the public URL of your service. Without it, the URL is made from the REST configuration of Camel, which the provider often cannot reach.
- route:
from:
uri: webhook:telegram:bots
parameters:
authorizationToken: "{{telegram.token}}"
webhookExternalUrl: "https://camel.example.com"
webhookComponentName: platform-http
steps:
- to:
uri: log:info The REST endpoint uses a REST component of the application. When there is more than one, as with camel run, set webhookComponentName, for example to platform-http. The path of the endpoint is webhookPath, or a hash of the delegate URI, after webhookBasePath when it is set.
The webhook options can also be set once on the component, for example in application.properties:
camel.component.webhook.webhook-external-url = https://camel.example.com