AWS Eventbridge
Since Camel 3.6
Both producer and consumer are supported
The AWS2 Eventbridge component manages the rules and targets of an AWS Eventbridge event bus, sends events to it, and consumes its events.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Eventbridge. More information is available at Amazon Eventbridge.
| To create a rule that triggers on an action by an AWS service that does not emit events, you can base the rule on API calls made by that service. The API calls are recorded by AWS CloudTrail, so you’ll need to have CloudTrail enabled. For more information, check Services Supported by CloudTrail Event History. |
URI Format
aws2-eventbridge://eventbusNameOrArn[?options]
The path is the name or the ARN of the event bus, such as default.
You can append query options to the URI in the following format:
?options=value&option2=value&…
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 AWS Eventbridge component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Component configuration. | EventbridgeConfiguration | ||
The location of a JSON file with the event pattern of the rule, for the putRule operation, which reads the file on every call. It is loaded from the classpath by default; use the prefix file: or http: to load it from another location. The CamelAwsEventbridgeEventPattern header replaces it, and putRule fails when neither is set. | String | ||
Required The operation that the producer performs. The CamelAwsEventbridgeOperation header replaces this option. Enum values:
| putRule | EventbridgeOperations | |
Whether the EventBridge client sends the requests to the URI of the uriEndpointOverride option instead of the EventBridge endpoint of the region. The SQS client of the consumer then sends its requests to that URI too. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request of the AWS SDK for the operation, such as a PutRuleRequest for putRule or a PutEventsRequest for putEvent. If true, the producer sends that request as it is, without the event bus of the endpoint, the eventPatternFile option or the headers, and a body of another type fails. If false, the producer builds the request from the event bus of the endpoint, the options and the headers. | false | boolean | |
The ID of the AWS region of EventBridge, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). The SQS client of the consumer uses this region too. If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The URI that the EventBridge client sends the requests to, for example http://localhost:4566 for a local emulator. The SQS client of the consumer uses it too, so it must serve SQS as well. It is used only when overrideEndpoint is true. | String | ||
Whether the consumer creates an SQS queue when it starts, if queueUrl is not set, with an access policy that lets only the rule send messages to it, and adds the queue as a target of the rule. If false, queueUrl is required. | true | boolean | |
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 to delete the auto-created SQS queue and remove the EventBridge target on shutdown. When false, the queue and its target are kept, so the queue collects the events while the consumer is stopped, and the queue name is derived from the event bus and the rule name, so the next start reuses the queue. | true | boolean | |
The maximum number of messages that one poll receives from the SQS queue, from 1 to 10. SQS rejects a value out of this range, which fails every poll. | 10 | int | |
The URL of an existing SQS queue that the consumer adds as a target of the rule and receives the events from, instead of creating a queue. The consumer does not change the access policy of the queue, which must allow EventBridge (events.amazonaws.com) to send messages to it. The target stays on the rule on shutdown, so the queue keeps collecting the events. If set, autoCreateQueue is not used. | String | ||
The name of the rule, on the event bus of the endpoint, whose events the consumer receives: the consumer adds its SQS queue as a target of the rule, so the event pattern of the rule selects the events. The rule must exist. Required for the consumer; the producer takes the rule name from the CamelAwsEventbridgeRuleName header instead. | String | ||
How long, in seconds, the messages that a poll receives stay hidden from other receive requests, from 0 to 43200 (12 hours). The consumer deletes a message when its exchange completes. A message whose exchange fails, or is not done within this time, becomes visible again and is received again. | 30 | int | |
How long, in seconds, a poll waits for a message to arrive in an empty SQS queue (long polling), from 0 to 20. The poll returns as soon as a message is available, and 0 returns at once (short polling). | 20 | int | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
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 | |
Autowired To use a custom software.amazon.awssdk.services.eventbridge.EventBridgeClient, which is autowired when the registry has a single one. When this option is set, the EventBridge client does not use the credentials, region, proxy, endpoint override and trustAllCertificates options, but the consumer still uses them for its SQS client. The endpoint does not close a client that is set or autowired. | EventBridgeClient | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the EventBridge client, and the SQS client of the consumer, use. The clients use a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the EventBridge client, and the SQS client of the consumer, use. The clients use a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the EventBridge client, and the SQS client of the consumer, use. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless eventbridgeClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless eventbridgeClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the EventBridge client, and the SQS client of the consumer, accept any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS Eventbridge endpoint is configured using URI syntax:
aws2-eventbridge://eventbusNameOrArn
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The location of a JSON file with the event pattern of the rule, for the putRule operation, which reads the file on every call. It is loaded from the classpath by default; use the prefix file: or http: to load it from another location. The CamelAwsEventbridgeEventPattern header replaces it, and putRule fails when neither is set. | String | ||
Required The operation that the producer performs. The CamelAwsEventbridgeOperation header replaces this option. Enum values:
| putRule | EventbridgeOperations | |
Whether the EventBridge client sends the requests to the URI of the uriEndpointOverride option instead of the EventBridge endpoint of the region. The SQS client of the consumer then sends its requests to that URI too. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request of the AWS SDK for the operation, such as a PutRuleRequest for putRule or a PutEventsRequest for putEvent. If true, the producer sends that request as it is, without the event bus of the endpoint, the eventPatternFile option or the headers, and a body of another type fails. If false, the producer builds the request from the event bus of the endpoint, the options and the headers. | false | boolean | |
The ID of the AWS region of EventBridge, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). The SQS client of the consumer uses this region too. If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The URI that the EventBridge client sends the requests to, for example http://localhost:4566 for a local emulator. The SQS client of the consumer uses it too, so it must serve SQS as well. It is used only when overrideEndpoint is true. | String | ||
Whether the consumer creates an SQS queue when it starts, if queueUrl is not set, with an access policy that lets only the rule send messages to it, and adds the queue as a target of the rule. If false, queueUrl is required. | true | boolean | |
Whether to delete the auto-created SQS queue and remove the EventBridge target on shutdown. When false, the queue and its target are kept, so the queue collects the events while the consumer is stopped, and the queue name is derived from the event bus and the rule name, so the next start reuses the queue. | true | boolean | |
The maximum number of messages that one poll receives from the SQS queue, from 1 to 10. SQS rejects a value out of this range, which fails every poll. | 10 | int | |
The URL of an existing SQS queue that the consumer adds as a target of the rule and receives the events from, instead of creating a queue. The consumer does not change the access policy of the queue, which must allow EventBridge (events.amazonaws.com) to send messages to it. The target stays on the rule on shutdown, so the queue keeps collecting the events. If set, autoCreateQueue is not used. | String | ||
The name of the rule, on the event bus of the endpoint, whose events the consumer receives: the consumer adds its SQS queue as a target of the rule, so the event pattern of the rule selects the events. The rule must exist. Required for the consumer; the producer takes the rule name from the CamelAwsEventbridgeRuleName header instead. | String | ||
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
How long, in seconds, the messages that a poll receives stay hidden from other receive requests, from 0 to 43200 (12 hours). The consumer deletes a message when its exchange completes. A message whose exchange fails, or is not done within this time, becomes visible again and is received again. | 30 | int | |
How long, in seconds, a poll waits for a message to arrive in an empty SQS queue (long polling), from 0 to 20. The poll returns as soon as a message is available, and 0 returns at once (short polling). | 20 | int | |
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 | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.eventbridge.EventBridgeClient, which is autowired when the registry has a single one. When this option is set, the EventBridge client does not use the credentials, region, proxy, endpoint override and trustAllCertificates options, but the consumer still uses them for its SQS client. The endpoint does not close a client that is set or autowired. | EventBridgeClient | ||
The host name of the proxy that the EventBridge client, and the SQS client of the consumer, use. The clients use a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the EventBridge client, and the SQS client of the consumer, use. The clients use a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the EventBridge client, and the SQS client of the consumer, use. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless eventbridgeClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless eventbridgeClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the EventBridge client, and the SQS client of the consumer, accept any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Eventbridge component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsEventbridgeOperation (common) Constant: | The operation to perform, which replaces the operation option. | String | |
CamelAwsEventbridgeRuleName (common) Constant: | The name of the rule, for the putRule, putTargets, removeTargets, deleteRule, enableRule, disableRule, describeRule and listTargetsByRule operations, which AWS rejects without it. putRule creates the rule, or updates the rule with this name. | String | |
CamelAwsEventbridgeRuleNamePrefix (common) Constant: | For listRules: list only the rules whose name starts with this prefix. If not set, all the rules of the event bus are listed. | String | |
CamelAwsEventbridgeEventPattern (common) Constant: | For putRule: the event pattern of the rule, as JSON text. It replaces the eventPatternFile option, and putRule fails when neither is set. | String | |
CamelAwsEventbridgeTargets (common) Constant: | For putTargets: the targets to add to the rule, as a collection of the Target of the AWS SDK. A target with the ID of a target of the rule replaces it. Required. | Collection | |
CamelAwsEventbridgeTargetsIds (common) Constant: | For removeTargets: the IDs of the targets to remove from the rule. Required. | Collection | |
CamelAwsEventbridgeTargetArn (common) Constant: | For listRuleNamesByTarget: the ARN of the target, such as an SQS queue, whose rules to list. AWS rejects the request without it. | String | |
CamelAwsEventbridgeResourcesArn (common) Constant: | For putEvent: the ARNs of the AWS resources that the event concerns, as a comma-separated list. Required. | String | |
CamelAwsEventbridgeSource (common) Constant: | For putEvent: the source of the event, which names the application that sends it, such as com.mycompany.myapp. Required. | String | |
CamelAwsEventbridgeDetailType (common) Constant: | For putEvent: the detail type of the event, free-form text that tells, together with the source, what kind of event it is. Required. | String | |
CamelAwsEventbridgeNextToken (listRules listTargetsByRule listRuleNamesByTarget) Constant: | The token of the page of results to get, from this header of the previous response. The producer sets it to the token of the next page, or to null on the last page. | String | |
CamelAwsEventbridgeLimit (listRules listTargetsByRule listRuleNamesByTarget) Constant: | The maximum number of results on one page, from 1 to 100. | Integer | |
CamelAwsEventbridgeIsTruncated (listRules listTargetsByRule listRuleNamesByTarget) Constant: | Set by the producer: true when there are more results, which the CamelAwsEventbridgeNextToken header gets. | Boolean | |
CamelAwsEventbridgeRuleArn (putRule describeRule) Constant: | The Amazon Resource Name (ARN) of the rule. | String | |
CamelAwsEventbridgeFailedEntryCount (putEvent putTargets removeTargets) Constant: | The number of failed entries in the response. The putEvent operation fails the exchange when an entry failed. | Integer | |
CamelAwsEventbridgeMessageId (consumer) Constant: | The ID of the SQS message that carried the event. | String | |
CamelAwsEventbridgeReceiptHandle (consumer) Constant: | The receipt handle of the SQS message, with which the consumer deletes the message from the queue when the exchange completes. | String |
Message Body
The message body at each side of the AWS Eventbridge 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 event as JSON text, one message per event the rule sends to the SQS queue of the consumer: the envelope of EventBridge, with the data of the event in its detail field, and the id of the SQS message in a header. |
Producer input |
| Not used by putRule, the default, and the other operations, which take their input from headers and the eventPatternFile option. putEvent sends the body as the detail of the event, which must be a JSON object as text: bytes, a stream or a file are read as text, a Map or a POJO is sent as its toString(), so marshal it first, and no body fails. With pojoRequest=true the request of the AWS SDK, such as a PutEventsRequest.
|
Producer output |
| The response of the AWS SDK for the operation: a PutRuleResponse for putRule, the default, and a PutEventsResponse for putEvent. An event that AWS rejects, such as one whose detail is not a JSON object, fails the exchange with the error code and message of the rejected event. |
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
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
AWS2-Eventbridge Producer operations
Camel-AWS2-Eventbridge component provides the following operation on the producer side:
-
putRule
-
putTargets
-
removeTargets
-
deleteRule
-
enableRule
-
disableRule
-
listRules
-
describeRule
-
listTargetsByRule
-
listRuleNamesByTarget
-
putEvent
-
PutRule: this operation creates a rule related to an eventbus
-
Java
-
XML
-
YAML
from("direct:putRule")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=putRule&eventPatternFile=file:src/test/resources/eventpattern.json")
.to("mock:result"); <route>
<from uri="direct:putRule"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=putRule&eventPatternFile=file:src/test/resources/eventpattern.json"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:putRule
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: putRule
eventPatternFile: "file:src/test/resources/eventpattern.json"
- to:
uri: mock:result This operation will create a rule named firstrule, and it will use a json file for defining the EventPattern. The event pattern is taken from the CamelAwsEventbridgeEventPattern header, else from the file of the eventPatternFile option; the operation fails when neither is set.
-
PutTargets: this operation will add a target to the rule
Target.builder() to construct target objectsfrom("direct:start")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsEventbridgeRuleName", "firstrule");
Target target = Target.builder().id("sqs-queue")
.arn("arn:aws:sqs:eu-west-1:780410022472:camel-connector-test")
.build();
List<Target> targets = new ArrayList<>();
targets.add(target);
exchange.getIn().setHeader("CamelAwsEventbridgeTargets", targets);
})
.to("aws2-eventbridge://test?operation=putTargets")
.to("mock:result"); This operation will add the target sqs-queue with the arn reported to the targets of the firstrule rule.
-
RemoveTargets: this operation will remove a collection of targets from the rule
List<String> to specify target IDs for removalfrom("direct:start")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsEventbridgeRuleName", "firstrule");
List<String> ids = new ArrayList<>();
ids.add("sqs-queue");
exchange.getIn().setHeader("CamelAwsEventbridgeTargetsIds", ids);
})
.to("aws2-eventbridge://test?operation=removeTargets")
.to("mock:result"); This operation will remove the target sqs-queue from the firstrule rule.
-
DeleteRule: this operation will delete a rule related to an eventbus
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=deleteRule")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=deleteRule"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: deleteRule
- to:
uri: mock:result This operation will remove the firstrule rule from the test eventbus.
-
EnableRule: this operation will enable a rule related to an eventbus
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=enableRule")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=enableRule"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: enableRule
- to:
uri: mock:result This operation will enable the firstrule rule from the test eventbus.
-
DisableRule: this operation will disable a rule related to an eventbus
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=disableRule")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=disableRule"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: disableRule
- to:
uri: mock:result This operation will disable the firstrule rule from the test eventbus.
-
ListRules: this operation will list all the rules related to an eventbus with prefix first
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleNamePrefix", constant("first"))
.to("aws2-eventbridge://test?operation=listRules")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleNamePrefix">
<constant>first</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=listRules"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleNamePrefix
constant: first
- to:
uri: aws2-eventbridge://test
parameters:
operation: listRules
- to:
uri: mock:result This operation will list all the rules with prefix first from the test eventbus.
-
DescribeRule: this operation will describe a specified rule related to an eventbus
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=describeRule")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=describeRule"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: describeRule
- to:
uri: mock:result This operation will describe the firstrule rule from the test eventbus.
-
ListTargetsByRule: this operation will return a list of targets associated with a rule
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeRuleName", constant("firstrule"))
.to("aws2-eventbridge://test?operation=listTargetsByRule")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>firstrule</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=listTargetsByRule"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: firstrule
- to:
uri: aws2-eventbridge://test
parameters:
operation: listTargetsByRule
- to:
uri: mock:result This operation will return a list of targets associated with the firstrule rule.
-
ListRuleNamesByTarget: this operation will return a list of rules associated with a target
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeTargetArn", constant("arn:aws:sqs:eu-west-1:123456789012:my-queue"))
.to("aws2-eventbridge://test?operation=listRuleNamesByTarget")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeTargetArn">
<constant>arn:aws:sqs:eu-west-1:123456789012:my-queue</constant>
</setHeader>
<to uri="aws2-eventbridge://test?operation=listRuleNamesByTarget"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeTargetArn
constant: "arn:aws:sqs:eu-west-1:123456789012:my-queue"
- to:
uri: aws2-eventbridge://test
parameters:
operation: listRuleNamesByTarget
- to:
uri: mock:result This operation will return a list of rules associated with a target.
-
PutEvent: this operation will send an event to the event bus, with the message body as the detail of the event, which must be a JSON object as text
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsEventbridgeResourcesArn", constant("arn:aws:sqs:eu-west-1:780410022472:camel-connector-test"))
.setHeader("CamelAwsEventbridgeSource", constant("com.pippo"))
.setHeader("CamelAwsEventbridgeDetailType", constant("peppe"))
.setBody(constant("{\"message\": \"Test Event\"}"))
.to("aws2-eventbridge://test?operation=putEvent")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsEventbridgeResourcesArn">
<constant>arn:aws:sqs:eu-west-1:780410022472:camel-connector-test</constant>
</setHeader>
<setHeader name="CamelAwsEventbridgeSource">
<constant>com.pippo</constant>
</setHeader>
<setHeader name="CamelAwsEventbridgeDetailType">
<constant>peppe</constant>
</setHeader>
<setBody>
<constant>{"message": "Test Event"}</constant>
</setBody>
<to uri="aws2-eventbridge://test?operation=putEvent"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsEventbridgeResourcesArn
constant: "arn:aws:sqs:eu-west-1:780410022472:camel-connector-test"
- setHeader:
name: CamelAwsEventbridgeSource
constant: com.pippo
- setHeader:
name: CamelAwsEventbridgeDetailType
constant: peppe
- setBody:
constant: '{"message": "Test Event"}'
- to:
uri: aws2-eventbridge://test
parameters:
operation: putEvent
- to:
uri: mock:result This operation will return the PutEventsResponse with the ID of the sent event. The exchange fails when EventBridge rejects the event, for example a detail that is not a JSON object is rejected with MalformedDetail; the exception gives the error code and message of the rejected event, and the CamelAwsEventbridgeFailedEntryCount header is still set. A message without a body fails with an InvalidPayloadException.
Consuming Events from EventBridge
Since Camel 4.19, the component supports consuming events from EventBridge rules using an SQS-backed polling pattern.
AWS EventBridge is an event router, not a message queue — it does not provide a pull-based API. The consumer works by wiring an SQS queue as a target of the specified EventBridge rule and then polling that queue for events. This is the standard AWS pattern for programmatically consuming EventBridge events.
How It Works
-
On startup the consumer creates an SQS queue (unless you provide one via
queueUrl). -
It sets an SQS queue policy that allows only the EventBridge rule given by
ruleNameto send messages (anaws:SourceArncondition with the ARN of the rule, which the consumer gets withDescribeRule). A queue given withqueueUrlkeeps its own policy. -
It adds the queue as a target of the EventBridge rule specified by
ruleName. -
It polls the SQS queue on schedule, delivering each event into the Camel route.
-
Successfully processed messages are deleted from the queue; failed messages remain for retry.
-
On shutdown the target of an auto-created queue is removed and the queue is deleted (configurable). A queue given with
queueUrlkeeps its target, so it collects the events while no consumer runs, and all the consumers that share it use the same target (its id is derived from the queue ARN).
An auto-created queue has a random part in its name, so every consumer has its own queue, which is deleted on shutdown. With deleteQueueOnShutdown=false, the consumer creates a durable queue instead: its name is camel-eventbridge-<rule name>-<hash of the event bus and the rule name>, so the next start reuses the queue (SQS CreateQueue returns the existing queue), and the queue keeps its target on shutdown, like a queue given with queueUrl. The queue collects the events while the consumer is stopped, and the consumers of the rule that use deleteQueueOnShutdown=false share one queue (they compete for the events instead of each getting a copy). Delete the queue yourself when the route is no longer used.
Consumer Configuration Options
| Option | Default | Type | Description |
|---|---|---|---|
| String | Required. The EventBridge rule name to consume events from. | |
| String | URL of an existing SQS queue to use. If omitted, a queue is auto-created. | |
|
| boolean | Whether to auto-create an SQS queue and wire it as the rule target. |
|
| boolean | Whether to delete the auto-created queue and remove the EventBridge target on shutdown. When |
|
| int | Maximum number of SQS messages to receive per poll cycle. |
|
| int | SQS long-polling wait time in seconds. |
|
| int | Seconds that received messages are hidden from subsequent polls. |
Standard ScheduledPollConsumer options (delay, initialDelay, greedy, etc.) are also available.
Consumer Example — Auto-Created Queue
-
Java
-
XML
-
YAML
from("aws2-eventbridge://default?ruleName=my-rule&delay=5000")
.log("Received EventBridge event: ${body}")
.to("direct:process"); <route>
<from uri="aws2-eventbridge://default?ruleName=my-rule&delay=5000"/>
<log message="Received EventBridge event: ${body}"/>
<to uri="direct:process"/>
</route> - route:
from:
uri: aws2-eventbridge://default
parameters:
ruleName: my-rule
delay: 5000
steps:
- log:
message: "Received EventBridge event: ${body}"
- to:
uri: direct:process The consumer auto-creates an SQS queue, wires it to the my-rule EventBridge rule, and polls every 5 seconds.
Consumer Example — User-Provided Queue
-
Java
-
XML
-
YAML
from("aws2-eventbridge://default?ruleName=my-rule&autoCreateQueue=false&queueUrl=https://sqs.us-east-1.amazonaws.com/123456789012/my-queue")
.log("Received: ${body}")
.to("direct:process"); <route>
<from uri="aws2-eventbridge://default?ruleName=my-rule&autoCreateQueue=false&queueUrl=https://sqs.us-east-1.amazonaws.com/123456789012/my-queue"/>
<log message="Received: ${body}"/>
<to uri="direct:process"/>
</route> - route:
from:
uri: aws2-eventbridge://default
parameters:
ruleName: my-rule
autoCreateQueue: false
queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/my-queue"
steps:
- log:
message: "Received: ${body}"
- to:
uri: direct:process Use this when you manage the SQS queue and its policy yourself.
Consumer Example — Combined Producer and Consumer
-
Java
-
XML
-
YAML
// First create the rule
from("direct:setup")
.setHeader("CamelAwsEventbridgeRuleName", constant("my-rule"))
.to("aws2-eventbridge://default?operation=putRule&eventPatternFile=file:eventpattern.json");
// Consume events matching the rule
from("aws2-eventbridge://default?ruleName=my-rule&delay=2000")
.log("Event: ${body}")
.to("mock:events"); <!-- First create the rule -->
<route>
<from uri="direct:setup"/>
<setHeader name="CamelAwsEventbridgeRuleName">
<constant>my-rule</constant>
</setHeader>
<to uri="aws2-eventbridge://default?operation=putRule&eventPatternFile=file:eventpattern.json"/>
</route>
<!-- Consume events matching the rule -->
<route>
<from uri="aws2-eventbridge://default?ruleName=my-rule&delay=2000"/>
<log message="Event: ${body}"/>
<to uri="mock:events"/>
</route> # First create the rule
- route:
from:
uri: direct:setup
steps:
- setHeader:
name: CamelAwsEventbridgeRuleName
constant: my-rule
- to:
uri: aws2-eventbridge://default
parameters:
operation: putRule
eventPatternFile: "file:eventpattern.json"
# Consume events matching the rule
- route:
from:
uri: aws2-eventbridge://default
parameters:
ruleName: my-rule
delay: 2000
steps:
- log:
message: "Event: ${body}"
- to:
uri: mock:events IAM Permissions
The consumer’s IAM principal needs the following permissions:
-
events:PutTargetsandevents:RemoveTargetson the EventBridge rule -
events:DescribeRuleon the EventBridge rule (if auto-creating) -
sqs:CreateQueue,sqs:DeleteQueue,sqs:SetQueueAttributes(if auto-creating) -
sqs:GetQueueAttributes,sqs:ReceiveMessage,sqs:DeleteMessageon the SQS queue
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-eventbridge</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.