0

we are using GCP PubSub extensively, using the functional binder approach from spring cloud steam:

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-pubsub-stream-binder</artifactId>
        </dependency>

, and org.springframework.cloud.stream.function.StreamBridge

Is anyone aware of recommended way to intercept such messages? Our use case is we need to manually add a trace identifier to each message. I was looking at using a ChannelInterceptor (e.g. below, which works fine, but not sure if good idea) or an Aspect. Re the Aspect, i have tried a few Point cuts with no joy.

@GlobalChannelInterceptor(patterns = ["[*-out]"])
class OutboundChannelInterceptor : ChannelInterceptor {
    override fun preSend(message: Message<*>, channel: MessageChannel): Message<*> {
        val mutableAccessor = MessageHeaderAccessor.getMutableAccessor(message)
        mutableAccessor.setHeader("aha", System.currentTimeMillis())
        return GenericMessage(message.payload, mutableAccessor.messageHeaders)
    }
}

Any advice much appreciated, thanks

Damo
  • 1,449
  • 3
  • 16
  • 29
  • I got these Aspects working, but again, if anyone has advice as to what is best practise / cleaner, that would be great: – Damo May 11 '21 at 20:00
  • @Around("execution(com.google.cloud.pubsub.v1.Subscriber com.google.cloud.spring.pubsub.support.SubscriberFactory.createSubscriber(String, com.google.cloud.pubsub.v1.MessageReceiver))") – Damo May 11 '21 at 20:00
  • @Around("execution(org.springframework.util.concurrent.ListenableFuture com.google.cloud.spring.pubsub.core.PubSubOperations.publish(String, Object, java.util.Map))") – Damo May 11 '21 at 20:00

0 Answers0