Class AbstractPulsarHeaderMapper<ToPulsarHeadersContextType,ToSpringHeadersContextType>
- Type Parameters:
ToPulsarHeadersContextType
- type of context object used in thetoPulsarHeaders(org.springframework.messaging.MessageHeaders)
APIToSpringHeadersContextType
- type of context object used in thetoSpringHeaders(org.apache.pulsar.client.api.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(java.lang.String, java.lang.Object, ToPulsarHeadersContextType)
and toSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType)
methods.
- Author:
- Chris Bono
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractPulsarHeaderMapper
(List<String> inboundPatterns, List<String> outboundPatterns) Construct a mapper that will match the supplied inbound and outbound patterns. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
matchesForInbound
(String header) Determine if a header name matches any of the currently configured list of inbound matchers.protected boolean
matchesForOutbound
(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 void
toPulsarHeadersOnCompleted
(MessageHeaders springHeaders, Map<String, String> pulsarHeaders, ToPulsarHeadersContextType context) Called at the end of a successfultoSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation.protected ToPulsarHeadersContextType
toPulsarHeadersOnStarted
(MessageHeaders springHeaders) Called at the beginning of everytoPulsarHeaders(org.springframework.messaging.MessageHeaders)
invocation and the returned value is passed into eachtoPulsarHeaderValue(java.lang.String, java.lang.Object, ToPulsarHeadersContextType)
invocation as well as the finaltoPulsarHeadersOnCompleted(org.springframework.messaging.MessageHeaders, java.util.Map<java.lang.String, java.lang.String>, ToPulsarHeadersContextType)
.protected abstract String
toPulsarHeaderValue
(String name, Object value, 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 void
toSpringHeadersOnCompleted
(org.apache.pulsar.client.api.Message<?> pulsarMessage, MessageHeaders springHeaders, ToSpringHeadersContextType context) Called at the end of a successfultoPulsarHeaders(org.springframework.messaging.MessageHeaders)
invocation.protected ToSpringHeadersContextType
toSpringHeadersOnStarted
(org.apache.pulsar.client.api.Message<?> pulsarMessage) Called at the beginning of everytoSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation and the returned value is passed into eachtoSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType)
invocation as well as the finaltoSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?>, org.springframework.messaging.MessageHeaders, ToSpringHeadersContextType)
.protected abstract Object
toSpringHeaderValue
(String name, String value, 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: Internal framework headers are never mapped outbound. By default, the
"id"
and"timestamp"
headers are also excluded from outbound mapping 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:PulsarHeaderMapper
Map 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:
toPulsarHeaders
in interfacePulsarHeaderMapper
- Parameters:
springHeaders
- the Spring messaging headers- Returns:
- map of Pulsar message headers or an empty map for no headers.
-
toPulsarHeadersOnStarted
@Nullable protected ToPulsarHeadersContextType toPulsarHeadersOnStarted(MessageHeaders springHeaders) Called at the beginning of everytoPulsarHeaders(org.springframework.messaging.MessageHeaders)
invocation and the returned value is passed into eachtoPulsarHeaderValue(java.lang.String, java.lang.Object, ToPulsarHeadersContextType)
invocation as well as the finaltoPulsarHeadersOnCompleted(org.springframework.messaging.MessageHeaders, java.util.Map<java.lang.String, java.lang.String>, 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 String toPulsarHeaderValue(String name, 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 valuecontext
- 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(org.apache.pulsar.client.api.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:PulsarHeaderMapper
Map 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:
toSpringHeaders
in interfacePulsarHeaderMapper
- Parameters:
pulsarMessage
- the Pulsar message containing the headers to map- Returns:
- the Spring Messaging headers
-
toSpringHeadersOnStarted
@Nullable protected ToSpringHeadersContextType toSpringHeadersOnStarted(org.apache.pulsar.client.api.Message<?> pulsarMessage) Called at the beginning of everytoSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation and the returned value is passed into eachtoSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType)
invocation as well as the finaltoSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?>, org.springframework.messaging.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(org.springframework.messaging.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
-