Skip to content

Commit 23379aa

Browse files
committed
Improve CloudEvents documentation and javadocs
Update javadoc comments in `CloudEventMessageConverter` and `ToCloudEventsTransformer` to improve clarity and readability. Enhance the CloudEvents reference documentation to better explain how extensions are populated using pattern matching instead of SpEL expressions. Changes include: - Clarify `CloudEventMessageConverter` class-level javadoc - Improve `isNoFormat()` and `setNoFormat()` method documentation - Update reference docs to reflect extension patterns approach - Fix minor formatting issues (double spaces)
1 parent 3b5336c commit 23379aa

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

spring-integration-cloudevents/src/main/java/org/springframework/integration/cloudevents/transformer/CloudEventMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.messaging.converter.MessageConverter;
2929

3030
/**
31-
* Convert Spring Integration {@link Message}s to CloudEvents.
31+
* Convert Spring Integration {@link Message}s into CloudEvent messages.
3232
*
3333
* @author Glenn Renfro
3434
*
@@ -69,7 +69,7 @@ public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
6969
return CloudEventUtils.toReader(event).read(new MessageBuilderMessageWriter(this.cloudEventPrefix,
7070
this.specVersionKey, this.dataContentTypeKey, Objects.requireNonNull(headers)));
7171
}
72-
throw new MessageTransformationException("Unsupported payload type. Should be CloudEvent but was: " +
72+
throw new MessageTransformationException("Unsupported payload type. Should be CloudEvent but was: " +
7373
payload.getClass());
7474
}
7575

spring-integration-cloudevents/src/main/java/org/springframework/integration/cloudevents/transformer/ToCloudEventsTransformer.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,20 @@ public String getComponentType() {
229229
}
230230

231231
/**
232-
* Returns CloudEvent information to the header if no {@link EventFormat} is found for content type.
233-
* @return true if CloudEvent information should be added to header if no {@link EventFormat} is found.
232+
* Indicates whether CloudEvent metadata should be added to the message headers
233+
* when no {@link EventFormat} is available for the content type.
234+
* @return {@code true} if CloudEvent metadata should be added to headers
235+
* when no suitable {@link EventFormat} is found;
236+
* {@code false} otherwise
234237
*/
235238
public boolean isNoFormat() {
236239
return this.noFormat;
237240
}
238241

239242
/**
240-
* Set CloudEvent information to the header if no {@link EventFormat} is found for content type.
241-
* When true and no {@link EventFormat} is found for the content type, CloudEvents are sent with headers instead of
242-
* structured format.
243+
* Establishes if CloudEvent information is written to the header if no {@link EventFormat} is found for content
244+
* type. When true and no {@link EventFormat} is found for the content type, CloudEvents are sent with headers
245+
* instead of structured format.
243246
* @param noFormat true to disable format serialization
244247
*/
245248
public void setNoFormat(boolean noFormat) {

src/reference/antora/modules/ROOT/pages/cloudevents.adoc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ compile "org.springframework.integration:spring-integration-cloudevents:{project
3535
=== ToCloudEventsTransformer
3636

3737
The `ToCloudEventsTransformer` converts Spring Integration messages into CloudEvents compliant messages.
38-
This transformer provides support for the CloudEvents specification v1.0 with configurable output format and defining attributes and extensions using `Expression` s.
38+
This transformer provides support for the CloudEvents specification v1.0 with configurable output format and defining attributes using `Expression` s and identifying extensions in the message headers via patterns.
3939

4040
[[cloudevent-transformer-overview]]
4141
==== Overview
@@ -51,7 +51,8 @@ NOTE: Messages to be transformed must have a payload of `byte[]`.
5151
[[configure-transformer]]
5252
===== Configuring Transformer
5353

54-
The `ToCloudEventsTransformer` allows the user to use SpEL `Expression`s to populate the attributes as well as the extensions.
54+
The `ToCloudEventsTransformer` allows the user to use SpEL `Expression`s to populate the attributes.
55+
Extensions are populated from the headers using pattern matching.
5556

5657
====== Attribute Expressions
5758

@@ -68,22 +69,18 @@ ToCloudEventTransformer transformer = new ToCloudEventTransformer(null);
6869
transformer.setTypeExpression(new LiteralExpression("sampleType"));
6970
----
7071

71-
====== Extension Expressions
72+
====== Extension Patterns
7273

73-
The expressions constructor parameter is an array of `Expression` s.
74+
The extensionPatterns constructor parameter is an array of `Strings` s.
7475
If the array is `null`, then no extensions will be added to the CloudEvent.
75-
Each `Expression` in the array must return the type `Map<String, Object>`.
76-
Where the key is a `String` and the value is of type `Object`.
77-
In the example below the extensions are hard coded to return 3 `Map<String, Object>` objects each containing one extension.
76+
Each `pattern` in the array is the search criteria for finding the headers that need to be added as extensions to the new `CloudEvent`.
77+
In the example below the system will search for any header key that starts with the word `trace` and add those headers to the extensions for the `CloudEvent` message.
78+
Then it will search for any header that contains a key of 'span-id' as well as 'user-id' and add those headers as extensions if found.
7879

7980
[source,java]
8081
----
81-
ExpressionParser parser = new SpelExpressionParser();
82-
Expression[] extensionExpressions = {
83-
parser.parseExpression("{'trace-id' : 'trace-123'}"),
84-
parser.parseExpression("{'span-id' : 'span-456'}"),
85-
parser.parseExpression("{'user-id' : 'user-789'}")};
86-
return new ToCloudEventTransformer(extensionExpressions);
82+
String[] extensionPatterns = {"trace*", "span-id", "user-id"};
83+
return new ToCloudEventTransformer(extensionPatterns);
8784
----
8885

8986
[[cloudevent-attribute-defaults]]

0 commit comments

Comments
 (0)