Class PubSubHeaderMapper

java.lang.Object
com.google.cloud.spring.pubsub.integration.PubSubHeaderMapper
All Implemented Interfaces:
org.springframework.integration.mapping.HeaderMapper<Map<String,String>>

public class PubSubHeaderMapper extends Object implements org.springframework.integration.mapping.HeaderMapper<Map<String,String>>
Maps headers from PubsubMessages to Messages and vice-versa.

By default, filters out headers called "id", "timestamp", "gcp_pubsub_acknowledgement" or "nativeHeaders" on the Message to PubsubMessage header conversion.

  • Constructor Details

    • PubSubHeaderMapper

      public PubSubHeaderMapper()
  • Method Details

    • setOutboundHeaderPatterns

      public void setOutboundHeaderPatterns(String... outboundHeaderPatterns)
      Set the patterns of the headers to be mapped in fromHeaders(MessageHeaders, Map). First patterns take precedence.
      Parameters:
      outboundHeaderPatterns - header patterns to be mapped
    • setInboundHeaderPatterns

      public void setInboundHeaderPatterns(String... inboundHeaderPatterns)
      Set the patterns of the headers to be mapped in toHeaders(Map). First patterns take precedence.
      Parameters:
      inboundHeaderPatterns - header patterns to be mapped
    • fromHeaders

      public void fromHeaders(org.springframework.messaging.MessageHeaders messageHeaders, Map<String,String> pubsubMessageHeaders)
      Generate headers in PubsubMessage format from MessageHeaders. All headers are converted into strings.

      Will map only the headers that match the patterns in outboundHeaderPatternsMap.

      Specified by:
      fromHeaders in interface org.springframework.integration.mapping.HeaderMapper<Map<String,String>>
      Parameters:
      messageHeaders - headers to map from
      pubsubMessageHeaders - headers in their final format
    • toHeaders

      public Map<String,Object> toHeaders(Map<String,String> pubsubMessageHeaders)
      Generate headers in Message format from Map<String, String>.

      Will map only the headers that match the patterns in inboundHeaderPatternsMap.

      Specified by:
      toHeaders in interface org.springframework.integration.mapping.HeaderMapper<Map<String,String>>
      Parameters:
      pubsubMessageHeaders - headers in PubsubMessage format
      Returns:
      a map with headers in the Message format