All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lsdconsulting.interceptors.messaging.ErrorPublisherInterceptor.kt Maven / Gradle / Ivy

Go to download

Provides various interceptors to capture events for the lsd-core library to generate sequence diagrams

There is a newer version: 8.0.73
Show newest version
package io.lsdconsulting.interceptors.messaging

import com.lsd.core.LsdContext
import com.lsd.core.builders.MessageBuilder.Companion.messageBuilder
import com.lsd.core.domain.MessageType
import com.lsd.core.sanitise
import org.springframework.integration.channel.PublishSubscribeChannel
import org.springframework.messaging.Message
import org.springframework.messaging.MessageChannel
import org.springframework.messaging.support.ChannelInterceptor

class ErrorPublisherInterceptor(
    private val lsdContext: LsdContext,
    private val appName: String,
) : ChannelInterceptor {

    override fun preSend(message: Message<*>, channel: MessageChannel): Message<*> {
        val payload = message.payload.toString()
        val target = (channel as PublishSubscribeChannel).fullChannelName.sanitise()
        lsdContext.capture(
            messageBuilder()
                .id(lsdContext.idGenerator.next())
                .from(appName)
                .to(target)
                .label("Publish error event")
                .data(renderHtmlFor(message.headers, payload))
                .type(MessageType.ASYNCHRONOUS)
                .build()
        )
        return message
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy