Pubsubplus-connector-aws-kinesis get the event topic when consuming in Kinesis Data Stream

Hi,
apologize if this is in the wrong category. We are using the connector to stream json events into a Kinesis Data Stream. Until now we have subscribed only to one single topic in the queue connected to Kinesis, and it has been working fine.

Now we need to subscribe to more than one topics in one queue.
Question is how the Kinesis receiver side can tell which topic each event belongs to?
The destination in the binding names only the queue, like this:

SPRING_CLOUD_STREAM_BINDINGS_INPUT-0_DESTINATION: dp.kinesis.casino
SPRING_CLOUD_STREAM_BINDINGS_OUTPUT-0_DESTINATION: dp-kinesis-casino
- queueName: "dp.kinesis.casino"
    owner: "dp"
    deadMsgQueue: "dp.kinesis.casino.dmq"
    accessType: "exclusive"
    permission: "consume"
    subscription_topics:
      - "service/ledger/*/casino/>"

There are some header options in the user guide but the documentation could be improved.

Anyone knows if there is any header, or other option, making it possible to include the topic (service/ledger/something/casino/) in the payload or as a partition key for the receiving Data Stream dp-kinesis-casino

Maybe it is included already but we are not finding it?

@joli there is a header allowing for dynamic publishing endpoints that can use values from the incoming message called scst_targetDestination

This Kinesis connector uses the transform-headerssection of the config to define what you would like to set for various output headers.

The following should work:

solace:
  connector:
    workflows:
      <workflow-id>:
        enabled: true
        transform-headers:
          expressions:
            headers.scst_targetDestination = headers.solace_destination # might have to add .name after destination

This will take the incoming message header and make it where the kinesis destination goes.

I was unable to test this directly, but wanted to answer to help you along.

Thank you for the suggestion @amackenzie !

Unfortunately, the connector removes the topic header (solace_destination) before any transform runs, which is why we only got null values when trying.

We raised a support issue and now got a complete working solution from Solace :folded_hands:

If anyone else using the solace-pubsub-connector-aws-kinesis:1.0.1 is having the same problem, here is the answer we got:

Kinesis Data Streams records don’t support headers. Each record has only the message data and a partition key, so the topic name has to go into one of those two places.

The connector removes the topic header (solace_destination) before your transforms run, which is why you couldn’t use it. It can still be read from the original Solace message, which the connector keeps internally. The expression below reads the topic from there and puts it in a header called aws_partitionKey, which Kinesis uses as the partition key. Header transforms run before payload transforms, so you can also add the topic to the JSON body.

Example configuration:
Add the transform-headers and transform-payloads sections below to each workflow in your application.yml. Your existing settings can stay as they are.

solace:
  connector:
    workflows:
      0:
        enabled: true
        acknowledgment:
          publish-async: true
        transform-headers:
          expressions:
            # Use the Solace topic as the Kinesis partition key
            aws_partitionKey: "T(org.apache.commons.lang3.reflect.FieldUtils).readField(headers['acknowledgmentCallback'], 'messageContainer', true).message.destination.name"
        transform-payloads:
          expressions:
            # Send the message as clean JSON (no prefix)
            - transform: "#isPayloadBytes(payload) ? payload : payload.toString().getBytes(T(java.nio.charset.StandardCharsets).UTF_8)"

          expressions:
            - transform: "#isPayloadBytes(payload) ? payload : payload.toString().getBytes(T(java.nio.charset.StandardCharsets).UTF_8)"