Skip to content

Commit

Permalink
Exclude goog_ prefixed attributes from outbound Pub/Sub messages (b…
Browse files Browse the repository at this point in the history
…ackport) (#919)
  • Loading branch information
elefeint authored Jan 28, 2022
1 parent 40f720c commit 3b52203
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class PubSubHeaderMapper implements HeaderMapper<Map<String, String>> {
"!" + MessageHeaders.ID,
"!" + MessageHeaders.TIMESTAMP,
"!" + GcpPubSubHeaders.ORIGINAL_MESSAGE,
"!" + GcpPubSubHeaders.CLIENT,
"!" + NativeMessageHeaderAccessor.NATIVE_HEADERS,
"!" + MessageHistory.HEADER_NAME,
"*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ private GcpPubSubHeaders() {}

private static final String PREFIX = "gcp_pubsub_";

/** The client header text. */
public static final String CLIENT = "googclient_*";

/** The topic header text. */
public static final String TOPIC = PREFIX + "topic";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public class PubSubHeaderMapperTests {
/** used to check for exception messages and types. */
@Rule public ExpectedException expectedException = ExpectedException.none();

@Test
public void testFilterGoogleClientHeaders() {
PubSubHeaderMapper mapper = new PubSubHeaderMapper();
Map<String, Object> originalHeaders = new HashMap<>();
originalHeaders.put("my header", "pantagruel's nativity");
MessageHeaders internalHeaders = new MessageHeaders(originalHeaders);

originalHeaders.put("googclient_deliveryattempt", "header attached when DLQ is enabled");
originalHeaders.put("googclient_anyHeader", "any other possible headers");

Map<String, String> filteredHeaders = new HashMap<>();
mapper.fromHeaders(internalHeaders, filteredHeaders);
assertThat(filteredHeaders)
.hasSize(1)
.containsEntry("my header", "pantagruel's nativity");
}


@Test
public void testFilterHeaders() {
PubSubHeaderMapper mapper = new PubSubHeaderMapper();
Expand Down

0 comments on commit 3b52203

Please sign in to comment.