Skip to content

#605 add support for spring amqp #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
feat: support alternative cloudEvents prefix
Signed-off-by: Michele <lars.michele@tu-dortmund.de>
  • Loading branch information
lyca committed Mar 8, 2024
commit c1e0fbd4659473d0c78e76f3f1b5dbe28738a164
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/**
* A {@link MessageConverter} that can translate to and from a {@link Message} and a {@link CloudEvent}.
* The {@link CloudEventContext} is canonicalized, with key names given a {@code ce-} prefix in the
* The {@link CloudEventContext} is canonicalized, with key names given a {@code cloudEvents_} prefix in the
* {@link MessageProperties}.
*
* @author Lars Michele
Expand Down Expand Up @@ -62,6 +62,9 @@ private MessageReader createMessageReader(Message message) {

private String version(MessageProperties properties) {
Object header = properties.getHeader(CloudEventsHeaders.SPEC_VERSION);
if (header == null) {
header = properties.getHeader(CloudEventsHeaders.ALT_SPEC_VERSION);
}
return header == null ? null : header.toString();
}

Expand All @@ -77,6 +80,9 @@ private String contentType(MessageProperties properties) {
String contentType = properties.getContentType();
if (contentType == null) {
Object header = properties.getHeader(CloudEventsHeaders.CONTENT_TYPE);
if (header == null) {
header = properties.getHeader(CloudEventsHeaders.ALT_CONTENT_TYPE);
}
return header == null ? null : header.toString();
}
return contentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,40 @@

package io.cloudevents.spring.amqp;

/**
* Constants used throughout the Spring AMQP binding for cloud events.
*/
public class CloudEventsHeaders {

/**
* CloudEvent attributes MUST be prefixed with either "cloudEvents_" or "cloudEvents:" for use in the application-properties section.
*
* @see <a href="https://github.com/cloudevents/spec/blob/main/cloudevents/bindings/amqp-protocol-binding.md#3131-amqp-application-property-names">
* AMQP Protocol Binding for CloudEvents</a>
* */
*/
public static final String CE_PREFIX = "cloudEvents_";

/**
* CloudEvents AMQP consumers SHOULD understand the "cloudEvents" prefix with both the '_' and the ':' separators as permitted within the constraints of the client model.
*
* @see <a href="https://github.com/cloudevents/spec/blob/main/cloudevents/bindings/amqp-protocol-binding.md#3131-amqp-application-property-names">
* AMQP Protocol Binding for CloudEvents</a>
*/
public static final String ALT_CE_PREFIX = "cloudEvents:";
/**
* The spec version header name.
*/
public static final String SPEC_VERSION = CE_PREFIX + "specversion";

/**
* The alternative spec version header name.
*/
public static final String ALT_SPEC_VERSION = ALT_CE_PREFIX + "specversion";
/**
* The data content-type header name.
*/
public static final String CONTENT_TYPE = CE_PREFIX + "datacontenttype";

/**
* The alternative data content-type header name.
*/
public static final String ALT_CONTENT_TYPE = ALT_CE_PREFIX + "datacontenttype";
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ protected boolean isContentTypeHeader(String key) {

@Override
protected boolean isCloudEventsHeader(String key) {
return key != null && key.length() > CE_PREFIX.length() && StringUtils.startsWithIgnoreCase(key, CE_PREFIX);
return key != null && key.length() > CE_PREFIX.length() && (StringUtils.startsWithIgnoreCase(key, CE_PREFIX)
|| StringUtils.startsWithIgnoreCase(key, ALT_CE_PREFIX));
}

@Override
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy