Class AbstractPulsarHeaderMapper<ToPulsarHeadersContextType, ToSpringHeadersContextType>

java.lang.Object
org.springframework.pulsar.support.header.AbstractPulsarHeaderMapper<ToPulsarHeadersContextType, ToSpringHeadersContextType>
Type Parameters:
ToPulsarHeadersContextType - type of context object used in the toPulsarHeaders(MessageHeaders) API
ToSpringHeadersContextType - type of context object used in the toSpringHeaders(Message) API
All Implemented Interfaces:
PulsarHeaderMapper
Direct Known Subclasses:
JsonPulsarHeaderMapper, ToStringPulsarHeaderMapper

public abstract class AbstractPulsarHeaderMapper<ToPulsarHeadersContextType, ToSpringHeadersContextType> extends Object implements PulsarHeaderMapper
Base 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 Details

  • Constructor Details

    • AbstractPulsarHeaderMapper

      public AbstractPulsarHeaderMapper(List<String> inboundPatterns, List<String> outboundPatterns)
      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 to outboundPatterns.

      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 all
      outboundPatterns - the outbound patterns to match - or empty to match all (except internal framework headers and id/timestamp)
      See Also:
  • Method Details

    • toPulsarHeaders

      public Map<String,String> toPulsarHeaders(MessageHeaders springHeaders)
      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 interface PulsarHeaderMapper
      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 every toPulsarHeaders(MessageHeaders) invocation and the returned value is passed into each toPulsarHeaderValue(String, Object, ToPulsarHeadersContextType) invocation as well as the final toPulsarHeadersOnCompleted(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 name
      value - the Spring Messaging header value, possibly null
      context - 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 successful toSpringHeaders(Message) invocation. Allows concrete implementations the ability to do final logic/cleanup.
      Parameters:
      springHeaders - the Spring Messaging headers that were mapped
      pulsarHeaders - the resulting map of Pulsar message headers
      context - the optional context used for the mapping invocation
    • toSpringHeaders

      public MessageHeaders toSpringHeaders(org.apache.pulsar.client.api.Message<?> pulsarMessage)
      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 interface PulsarHeaderMapper
      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 every toSpringHeaders(Message) invocation and the returned value is passed into each toSpringHeaderValue(String, String, ToSpringHeadersContextType) invocation as well as the final toSpringHeadersOnCompleted(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 name
      value - the Pulsar header value
      context - 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 successful toPulsarHeaders(MessageHeaders) invocation. Allows concrete implementations the ability to do final logic/cleanup.
      Parameters:
      pulsarMessage - the Pulsar message whose headers were mapped
      springHeaders - the resulting Spring Messaging headers
      context - the optional context used for the mapping invocation
    • matchesForOutbound

      protected boolean matchesForOutbound(String header)
      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

      protected boolean matchesForInbound(String header)
      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