Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,83 @@ include::partial$component-endpoint-headers.adoc[]

== Usage

=== Message headers evaluated by the EventBridge producer

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Header |Type |Description

|`CamelAlibabaEventBridgeOperation` |`String` | Name of operation to invoke

|`CamelAlibabaEventBridgeEventBusName` |`String` | Event bus name to publish events to (overrides the endpoint option)

|`CamelAlibabaEventBridgeEventSource` |`String` | Event source URI (overrides the endpoint option)

|`CamelAlibabaEventBridgeEventType` |`String` | Event type (overrides the endpoint option)

|`CamelAlibabaEventBridgeEventSubject` |`String` | Event subject (overrides the endpoint option)

|=======================================================================

If any of the above headers are set, they will override their corresponding query parameter value.

=== Message headers set by the EventBridge producer

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Header |Type |Description

|`CamelAlibabaEventBridgeRequestId` |`String` | Alibaba Cloud request ID returned by EventBridge

|=======================================================================

=== Event payload Map keys evaluated by the producer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved — Map body schema documented

Input Map keys, response metadata structure, and String/JSON + Map + multi-event examples are all documented. Prior concern about the sourceeventSource rename is mitigated since this is a Preview 4.23 component not yet released.


When the message body is a `Map` (or `List<Map>` for publishing multiple events), the following keys are evaluated:

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Key |Type |Description

|`eventBusName` |`String` | Event bus name (overrides header or endpoint option)

|`eventSource` |`String` | Event source URI (overrides header or endpoint option)

|`eventType` |`String` | Event type (overrides header or endpoint option)

|`eventSubject` |`String` | Event subject (overrides header or endpoint option)

|`eventData` |`Object` | Event payload data (serialized to JSON)

|=======================================================================

=== Response metadata in message body

The `putEvents` producer operation returns structured response metadata in the message body (`Map<String, Object>`):

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Key |Type |Description

|`requestId` |`String` | Request identifier returned by EventBridge

|`resourceOwnerAccountId` |`String` | Resource owner account identifier

|`failedEntryCount` |`Integer` | Number of failed entries

|`entryList` |`List<Map>` | List of entry results, where each entry map contains `eventId`, `errorCode`, and `errorMessage`

|=======================================================================

=== Operations

The component supports the following operations:

* `putEvents` - publish one or more CloudEvents (producer)

=== Producer example
== Examples

=== Publish event with String / JSON body

[source,java]
----
Expand All @@ -59,6 +129,30 @@ from("direct:start")
.to("alibaba-eventbridge:putEvents?eventBusName=my-bus&eventSource=camel.test&eventType=OrderCreated&region=cn-hangzhou&accessKey=RAW(accessKey)&secretKey=RAW(secretKey)");
----

== Examples
=== Publish event with Map body

[source,java]
----
Map<String, Object> event = new HashMap<>();
event.put("eventBusName", "my-bus");
event.put("eventSource", "camel.test");
event.put("eventType", "OrderCreated");
event.put("eventSubject", "order/123");
event.put("eventData", Map.of("orderId", "123"));

from("direct:start")
.setBody(constant(event))
.to("alibaba-eventbridge:putEvents?region=cn-hangzhou&accessKey=RAW(accessKey)&secretKey=RAW(secretKey)");
----

=== Publish multiple events

[source,java]
----
from("direct:start")
.setBody(constant(List.of(event1, event2)))
.to("alibaba-eventbridge:putEvents?region=cn-hangzhou&accessKey=RAW(accessKey)&secretKey=RAW(secretKey)");
----

For more examples, see the unit tests in the `camel-alibaba-eventbridge` module.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.gson.Gson;
import org.apache.camel.Exchange;
import org.apache.camel.component.alibaba.common.OpenApiClientSupport;
import org.apache.camel.component.alibaba.eventbridge.constants.AlibabaEventBridgeConstants;
import org.apache.camel.component.alibaba.eventbridge.constants.AlibabaEventBridgeProperties;
import org.apache.camel.component.alibaba.eventbridge.models.ClientConfigurations;
import org.apache.camel.util.ObjectHelper;
Expand Down Expand Up @@ -99,11 +100,13 @@ private static CloudEvent toCloudEvent(Object body, ClientConfigurations configu
}

if (body instanceof Map<?, ?> mapBody) {
String eventBusName = stringValue(mapBody.get("eventBusName"), configuration.getEventBusName());
String source = stringValue(mapBody.get("source"), configuration.getEventSource());
String type = stringValue(mapBody.get("type"), configuration.getEventType());
String subject = stringValue(mapBody.get("subject"), configuration.getEventSubject());
String data = jsonDataValue(mapBody.get("data"));
String eventBusName
= stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_BUS_NAME), configuration.getEventBusName());
String source = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SOURCE), configuration.getEventSource());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map body keys renamed — document this

Previous Map keys were CloudEvents-short (source, type, subject, data); now aligned with URI params (eventSource, eventType, eventSubject, eventData). Fine for unreleased Preview, but please document the Map body schema in the component guide.

String type = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_TYPE), configuration.getEventType());
String subject
= stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SUBJECT), configuration.getEventSubject());
String data = jsonDataValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_DATA));

if (ObjectHelper.isEmpty(source) || ObjectHelper.isEmpty(type) || ObjectHelper.isEmpty(eventBusName)) {
throw new IllegalArgumentException("Event source, type and event bus name are required");
Expand Down Expand Up @@ -174,20 +177,21 @@ private static String jsonDataValue(Object value) {

public static Map<String, Object> toPutEventsMap(PutEventsResponse response) {
Map<String, Object> map = new HashMap<>();
map.put("requestId", response.getRequestId());
map.put("resourceOwnerAccountId", response.getResourceOwnerAccountId());
map.put("failedEntryCount", response.getFailedEntryCount());
map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_REQUEST_IDENTIFIER, response.getRequestId());
map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_RESOURCE_OWNER_ACCOUNT_IDENTIFIER,
response.getResourceOwnerAccountId());
map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_FAILED_ENTRY_COUNT, response.getFailedEntryCount());

if (response.getEntryList() != null) {
List<Map<String, Object>> entries = new ArrayList<>();
for (PutEventsResponseEntry entry : response.getEntryList()) {
Map<String, Object> entryMap = new HashMap<>();
entryMap.put("eventId", entry.getEventId());
entryMap.put("errorCode", entry.getErrorCode());
entryMap.put("errorMessage", entry.getErrorMessage());
entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ID, entry.getEventId());
entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ERROR_CODE, entry.getErrorCode());
entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ERROR_MESSAGE, entry.getErrorMessage());
entries.add(entryMap);
}
map.put("entryList", entries);
map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ENTRY_LIST, entries);
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.alibaba.eventbridge.constants;

/**
* Constants for Alibaba EventBridge payload and response dictionary keys.
*/
public final class AlibabaEventBridgeConstants {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved — plain constants, no incorrect @metadata

Good follow-up: payload and response dictionary keys are now plain String constants with class-level Javadoc, matching OSSConstants. This removes the prior javaType mismatches on failedEntryCount and entryList.


public static final String EVENT_BUS_NAME = "eventBusName";
public static final String EVENT_SOURCE = "eventSource";
public static final String EVENT_TYPE = "eventType";
public static final String EVENT_SUBJECT = "eventSubject";
public static final String EVENT_DATA = "eventData";

public static final String EVENT_RESPONSE_REQUEST_IDENTIFIER = "requestId";
public static final String EVENT_RESPONSE_RESOURCE_OWNER_ACCOUNT_IDENTIFIER = "resourceOwnerAccountId";
public static final String EVENT_RESPONSE_FAILED_ENTRY_COUNT = "failedEntryCount";
public static final String EVENT_RESPONSE_ID = "eventId";
public static final String EVENT_RESPONSE_ERROR_CODE = "errorCode";
public static final String EVENT_RESPONSE_ERROR_MESSAGE = "errorMessage";
public static final String EVENT_RESPONSE_ENTRY_LIST = "entryList";

private AlibabaEventBridgeConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@

import org.apache.camel.spi.Metadata;

public final class AlibabaEventBridgeHeaders {
public sealed class AlibabaEventBridgeHeaders permits AlibabaEventBridgeProperties {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sealed hierarchy — consider consistency

Sealed HeadersProperties deduplicates exchange keys nicely. Other Alibaba modules (OSS, KMS, SMS) use separate final classes. Worth aligning across CAMEL-24373 if a convention is emerging.


@Metadata(label = "producer", description = "Event bus name override", javaType = "String")
public static final String EVENT_BUS_NAME = AlibabaEventBridgeProperties.EVENT_BUS_NAME;
public static final String EVENT_BUS_NAME = "CamelAlibabaEventBridgeEventBusName";

@Metadata(label = "producer", description = "Event source override", javaType = "String")
public static final String EVENT_SOURCE = AlibabaEventBridgeProperties.EVENT_SOURCE;
public static final String EVENT_SOURCE = "CamelAlibabaEventBridgeEventSource";

@Metadata(label = "producer", description = "Event type override", javaType = "String")
public static final String EVENT_TYPE = AlibabaEventBridgeProperties.EVENT_TYPE;
public static final String EVENT_TYPE = "CamelAlibabaEventBridgeEventType";

@Metadata(label = "producer", description = "Event subject override", javaType = "String")
public static final String EVENT_SUBJECT = AlibabaEventBridgeProperties.EVENT_SUBJECT;
public static final String EVENT_SUBJECT = "CamelAlibabaEventBridgeEventSubject";

@Metadata(label = "producer", description = "Alibaba Cloud request id", javaType = "String")
public static final String REQUEST_ID = AlibabaEventBridgeProperties.REQUEST_ID;
public static final String REQUEST_ID = "CamelAlibabaEventBridgeRequestId";

private AlibabaEventBridgeHeaders() {
AlibabaEventBridgeHeaders() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,11 @@

import org.apache.camel.spi.Metadata;

public final class AlibabaEventBridgeProperties {
public final class AlibabaEventBridgeProperties extends AlibabaEventBridgeHeaders {

@Metadata(label = "producer", description = "Operation to perform", javaType = "String")
public static final String OPERATION = "CamelAlibabaEventBridgeOperation";

@Metadata(label = "producer", description = "Event bus name override", javaType = "String")
public static final String EVENT_BUS_NAME = "CamelAlibabaEventBridgeEventBusName";

@Metadata(label = "producer", description = "Event source override", javaType = "String")
public static final String EVENT_SOURCE = "CamelAlibabaEventBridgeEventSource";

@Metadata(label = "producer", description = "Event type override", javaType = "String")
public static final String EVENT_TYPE = "CamelAlibabaEventBridgeEventType";

@Metadata(label = "producer", description = "Event subject override", javaType = "String")
public static final String EVENT_SUBJECT = "CamelAlibabaEventBridgeEventSubject";

@Metadata(label = "producer", description = "Request id returned by EventBridge", javaType = "String")
public static final String REQUEST_ID = "CamelAlibabaEventBridgeRequestId";

private AlibabaEventBridgeProperties() {
}
}
Loading