Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exchange/routingKey to RabbitMessageSenderContext #2816

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ protected void observeTheSend(Channel channel, Message message, boolean mandator
ObservationRegistry registry = getObservationRegistry();
Observation observation = RabbitTemplateObservation.TEMPLATE_OBSERVATION.observation(this.observationConvention,
DefaultRabbitTemplateObservationConvention.INSTANCE,
() -> new RabbitMessageSenderContext(message, this.beanName, exch + "/" + rKey), registry);
() -> new RabbitMessageSenderContext(message, this.beanName, exch, rKey), registry);

observation.observe(() -> sendToRabbit(channel, exch, rKey, mandatory, message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ public class RabbitMessageSenderContext extends SenderContext<Message> {

private final String destination;

public RabbitMessageSenderContext(Message message, String beanName, String destination) {
private final String exchange;

private final String routingKey;

public RabbitMessageSenderContext(Message message, String beanName, String exchange, String routingKey) {
artembilan marked this conversation as resolved.
Show resolved Hide resolved
ngocnhan-tran1996 marked this conversation as resolved.
Show resolved Hide resolved
super((carrier, key, value) -> message.getMessageProperties().setHeader(key, value));
setCarrier(message);
this.beanName = beanName;
this.destination = destination;
this.exchange = exchange;
this.routingKey = routingKey;
this.destination = exchange + "/" + routingKey;
setRemoteServiceName("RabbitMQ");
}

Expand All @@ -53,4 +59,20 @@ public String getDestination() {
return this.destination;
}

/**
* Return the exchange.
* @return the exchange.
ngocnhan-tran1996 marked this conversation as resolved.
Show resolved Hide resolved
*/
public String getExchange() {
return this.exchange;
}

/**
* Return the routingKey.
* @return the routingKey.
*/
public String getRoutingKey() {
return this.routingKey;
}

}