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(org.springframework.messaging.MessageHeaders) API
ToSpringHeadersContextType - type of context object used in the toSpringHeaders(org.apache.pulsar.client.api.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(java.lang.String, java.lang.Object, ToPulsarHeadersContextType) and toSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType) methods.

  • Field Details

    • logger

      protected final org.springframework.core.log.LogAccessor logger
  • 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:
      • PatternMatchUtils.simpleMatch(String, String)
  • Method Details

    • toPulsarHeaders

      public Map<String,String> toPulsarHeaders(org.springframework.messaging.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

      @Nullable protected ToPulsarHeadersContextType toPulsarHeadersOnStarted(org.springframework.messaging.MessageHeaders springHeaders)
      Called at the beginning of every toPulsarHeaders(org.springframework.messaging.MessageHeaders) invocation and the returned value is passed into each toPulsarHeaderValue(java.lang.String, java.lang.Object, ToPulsarHeadersContextType) invocation as well as the final toPulsarHeadersOnCompleted(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 name
      value - the Spring Messaging header value
      context - the optional context used for the mapping invocation
      Returns:
      the Pulsar header value to use
    • toPulsarHeadersOnCompleted

      protected void toPulsarHeadersOnCompleted(org.springframework.messaging.MessageHeaders springHeaders, Map<String,String> pulsarHeaders, @Nullable ToPulsarHeadersContextType context)
      Called at the end of a successful toSpringHeaders(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 mapped
      pulsarHeaders - the resulting map of Pulsar message headers
      context - the optional context used for the mapping invocation
    • toSpringHeaders

      public org.springframework.messaging.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

      @Nullable protected ToSpringHeadersContextType toSpringHeadersOnStarted(org.apache.pulsar.client.api.Message<?> pulsarMessage)
      Called at the beginning of every toSpringHeaders(org.apache.pulsar.client.api.Message<?>) invocation and the returned value is passed into each toSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType) invocation as well as the final toSpringHeadersOnCompleted(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 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, org.springframework.messaging.MessageHeaders springHeaders, @Nullable ToSpringHeadersContextType context)
      Called at the end of a successful toPulsarHeaders(org.springframework.messaging.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