Class RabbitTraceHeaderCarrier
@Logged call chain's FlowContext across a
RabbitMQ message, by writing it into the message's properties when
publishing and reading it back when consuming.
The Spring AMQP counterpart to
com.fayupable.logged.spring.kafka.KafkaTraceHeaderCarrier: the
traceId and depth are written as plain entries in
MessageProperties.getHeaders(), never into the message body.
RabbitMQ message headers exist specifically for metadata like this: they
travel with the message but are entirely separate from whatever
serialization format the message body uses, so this never touches or
constrains that body's schema.
Like every propagation class in this library, nothing here is wired in
automatically. A consuming application calls writeToHeaders(org.springframework.amqp.core.MessageProperties) when
publishing a message and readAndAdopt(org.springframework.amqp.core.MessageProperties, java.lang.Runnable) when consuming one, exactly
where it already publishes or consumes RabbitMQ messages.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidreadAndAdopt(org.springframework.amqp.core.MessageProperties properties, Runnable work) Reads aFlowContextfromproperties, if present, adopts it as the active context on this thread for the duration ofwork, and restores this thread's previous context again afterward, regardless of whetherworkcompletes normally or throws.static voidwriteToHeaders(org.springframework.amqp.core.MessageProperties properties) Writes the current thread'sFlowContext, if any is active, intopropertiesasTRACE_ID_HEADER/DEPTH_HEADERheader entries.
-
Method Details
-
writeToHeaders
public static void writeToHeaders(org.springframework.amqp.core.MessageProperties properties) Writes the current thread'sFlowContext, if any is active, intopropertiesasTRACE_ID_HEADER/DEPTH_HEADERheader entries.Does nothing if no
@Loggedcall is currently active on this thread: a message published from outside any call chain simply carries no trace headers, exactly as if this method had never been called.- Parameters:
properties- the properties of the message about to be published
-
readAndAdopt
public static void readAndAdopt(org.springframework.amqp.core.MessageProperties properties, Runnable work) Reads aFlowContextfromproperties, if present, adopts it as the active context on this thread for the duration ofwork, and restores this thread's previous context again afterward, regardless of whetherworkcompletes normally or throws.If
propertiescarries noTRACE_ID_HEADER— for example, a message published by a service that does not use this library, or one published from outside any call chain —workis simply run as-is, with no context adopted. Any@Loggedcall made from within it then starts a new chain of its own, exactly as it would without this class involved at all.- Parameters:
properties- the properties of the message being consumedwork- the message-handling code to run with the message's trace context active
-