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

io.lsdconsulting.interceptors.rabbitmq.EventNameDeriver.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.rabbitmq

import org.springframework.amqp.core.MessageProperties

fun deriveEventName(messageProperties: MessageProperties, alternativeEventName: String?): String =
    deriveFromTypeIdHeader(messageProperties.getHeader(TYPE_ID_HEADER))
        ?: getDefaultExchangeName(alternativeEventName)

private fun getDefaultExchangeName(alternativeExchangeName: String?): String =
    if (!alternativeExchangeName.isNullOrBlank()) alternativeExchangeName else UNKNOWN_EVENT

private fun deriveFromTypeIdHeader(typeIdHeader: String?): String? =
    typeIdHeader?.split("\\.".toRegex())?.reduce { _: String?, second: String -> second }?.ifBlank { null }

private const val TYPE_ID_HEADER = "__TypeId__"
private const val UNKNOWN_EVENT = "UNKNOWN_EVENT"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy