Class AbstractPulsarHeaderMapper<ToPulsarHeadersContextType, ToSpringHeadersContextType>
- Type Parameters:
ToPulsarHeadersContextType- type of context object used in thetoPulsarHeaders(MessageHeaders)APIToSpringHeadersContextType- type of context object used in thetoSpringHeaders(Message)API
- All Implemented Interfaces:
PulsarHeaderMapper
- Direct Known Subclasses:
JsonPulsarHeaderMapper, ToStringPulsarHeaderMapper
PulsarHeaderMapper implementation that constrains which headers are mapped
via header matchers.
Concrete implementations only need to specify how to convert a header value to and from
Spring Messaging and Pulsar, by implementing the abstract toPulsarHeaderValue(String, Object, ToPulsarHeadersContextType)
and toSpringHeaderValue(String, String, ToSpringHeadersContextType) methods.
- Author:
- Chris Bono
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractPulsarHeaderMapper(List<String> inboundPatterns, List<String> outboundPatterns) Construct a mapper that will match the supplied inbound and outbound patterns. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanmatchesForInbound(String header) Determine if a header name matches any of the currently configured list of inbound matchers.protected booleanmatchesForOutbound(String header) Determine if a header name matches any of the currently configured list of outbound matchers.toPulsarHeaders(MessageHeaders springHeaders) Map from the given Spring Messaging headers to Pulsar message headers.protected voidtoPulsarHeadersOnCompleted(MessageHeaders springHeaders, Map<String, String> pulsarHeaders, @Nullable ToPulsarHeadersContextType context) Called at the end of a successfultoSpringHeaders(Message)invocation.protected @Nullable ToPulsarHeadersContextTypetoPulsarHeadersOnStarted(MessageHeaders springHeaders) Called at the beginning of everytoPulsarHeaders(MessageHeaders)invocation and the returned value is passed into eachtoPulsarHeaderValue(String, Object, ToPulsarHeadersContextType)invocation as well as the finaltoPulsarHeadersOnCompleted(MessageHeaders, Map, ToPulsarHeadersContextType).protected abstract @Nullable StringtoPulsarHeaderValue(String name, @Nullable Object value, @Nullable ToPulsarHeadersContextType context) Determine the Pulsar header value to use for a Spring Messaging header.toSpringHeaders(org.apache.pulsar.client.api.Message<?> pulsarMessage) Map the headers from the given Pulsar message to Spring Messaging headers.protected voidtoSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?> pulsarMessage, MessageHeaders springHeaders, @Nullable ToSpringHeadersContextType context) Called at the end of a successfultoPulsarHeaders(MessageHeaders)invocation.protected @Nullable ToSpringHeadersContextTypetoSpringHeadersOnStarted(org.apache.pulsar.client.api.Message<?> pulsarMessage) Called at the beginning of everytoSpringHeaders(Message)invocation and the returned value is passed into eachtoSpringHeaderValue(String, String, ToSpringHeadersContextType)invocation as well as the finaltoSpringHeadersOnCompleted(Message, MessageHeaders, ToSpringHeadersContextType).protected abstract ObjecttoSpringHeaderValue(String name, String value, @Nullable ToSpringHeadersContextType context) Determine the Spring Messaging header value to use for a Pulsar header.
-
Field Details
-
logger
-
-
Constructor Details
-
AbstractPulsarHeaderMapper
Construct a mapper that will match the supplied inbound and outbound patterns.NOTE: By default, internal framework headers and the
"id"and"timestamp"headers are not mapped outbound but can be included by adding them tooutboundPatterns.NOTE: The patterns are applied in order, stopping on the first match (positive or negative). When no pattern is specified, the
"*"pattern is added last. However, once a pattern is specified, the"*"is not added and must be added to the specified patterns if desired.- Parameters:
inboundPatterns- the inbound patterns to match - or empty to match alloutboundPatterns- the outbound patterns to match - or empty to match all (except internal framework headers and id/timestamp)- See Also:
-
-
Method Details
-
toPulsarHeaders
Description copied from interface:PulsarHeaderMapperMap from the given Spring Messaging headers to Pulsar message headers.Commonly used in the outbound flow when a Spring message is being converted to a Pulsar message in order to be written out to Pulsar topic (outbound).
- Specified by:
toPulsarHeadersin interfacePulsarHeaderMapper- Parameters:
springHeaders- the Spring messaging headers- Returns:
- map of Pulsar message headers or an empty map for no headers.
-
toPulsarHeadersOnStarted
protected @Nullable ToPulsarHeadersContextType toPulsarHeadersOnStarted(MessageHeaders springHeaders) Called at the beginning of everytoPulsarHeaders(MessageHeaders)invocation and the returned value is passed into eachtoPulsarHeaderValue(String, Object, ToPulsarHeadersContextType)invocation as well as the finaltoPulsarHeadersOnCompleted(MessageHeaders, Map, ToPulsarHeadersContextType). Allows concrete implementations the ability to create an arbitrary context object and have it passed through the mapping process.- Parameters:
springHeaders- the Spring Messaging headers that are being converted- Returns:
- optional context to pass through the mapping invocation
-
toPulsarHeaderValue
protected abstract @Nullable String toPulsarHeaderValue(String name, @Nullable Object value, @Nullable ToPulsarHeadersContextType context) Determine the Pulsar header value to use for a Spring Messaging header.- Parameters:
name- the Spring Messaging header namevalue- the Spring Messaging header value, possibly nullcontext- the optional context used for the mapping invocation- Returns:
- the Pulsar header value to use
-
toPulsarHeadersOnCompleted
protected void toPulsarHeadersOnCompleted(MessageHeaders springHeaders, Map<String, String> pulsarHeaders, @Nullable ToPulsarHeadersContextType context) Called at the end of a successfultoSpringHeaders(Message)invocation. Allows concrete implementations the ability to do final logic/cleanup.- Parameters:
springHeaders- the Spring Messaging headers that were mappedpulsarHeaders- the resulting map of Pulsar message headerscontext- the optional context used for the mapping invocation
-
toSpringHeaders
Description copied from interface:PulsarHeaderMapperMap the headers from the given Pulsar message to Spring Messaging headers.Commonly used in the inbound flow when an incoming Pulsar message is being converted to a Spring message.
- Specified by:
toSpringHeadersin interfacePulsarHeaderMapper- Parameters:
pulsarMessage- the Pulsar message containing the headers to map- Returns:
- the Spring Messaging headers
-
toSpringHeadersOnStarted
protected @Nullable ToSpringHeadersContextType toSpringHeadersOnStarted(org.apache.pulsar.client.api.Message<?> pulsarMessage) Called at the beginning of everytoSpringHeaders(Message)invocation and the returned value is passed into eachtoSpringHeaderValue(String, String, ToSpringHeadersContextType)invocation as well as the finaltoSpringHeadersOnCompleted(Message, MessageHeaders, ToSpringHeadersContextType). Allows concrete implementations the ability to create an arbitrary context object and have it passed through the mapping process.- Parameters:
pulsarMessage- the Pulsar message whose headers are being mapped- Returns:
- optional context to pass through the mapping invocation
-
toSpringHeaderValue
protected abstract Object toSpringHeaderValue(String name, String value, @Nullable ToSpringHeadersContextType context) Determine the Spring Messaging header value to use for a Pulsar header.- Parameters:
name- the Pulsar header namevalue- the Pulsar header valuecontext- the optional context used for the mapping invocation- Returns:
- the Spring Messaging header value to use
-
toSpringHeadersOnCompleted
protected void toSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?> pulsarMessage, MessageHeaders springHeaders, @Nullable ToSpringHeadersContextType context) Called at the end of a successfultoPulsarHeaders(MessageHeaders)invocation. Allows concrete implementations the ability to do final logic/cleanup.- Parameters:
pulsarMessage- the Pulsar message whose headers were mappedspringHeaders- the resulting Spring Messaging headerscontext- the optional context used for the mapping invocation
-
matchesForOutbound
Determine if a header name matches any of the currently configured list of outbound matchers.- Parameters:
header- the name of the header to check- Returns:
- whether the header matches for outbound
-
matchesForInbound
Determine if a header name matches any of the currently configured list of inbound matchers.- Parameters:
header- the name of the header to check- Returns:
- whether the header matches for inbound
-