Skip to content

Commit

Permalink
Handle RuntimeException when getting/setting JMS headers
Browse files Browse the repository at this point in the history
Currently JMSException is handled when getting/setting JMS headers.
Some JMS providers will throw RuntimeException instead of JMSException when failing to get/set JMS headers.
This change adds so that RuntimeException is also handled.
  • Loading branch information
cfredri4 committed Dec 18, 2024
1 parent 3383e5c commit d8fbfc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.micrometer.jakarta9.instrument.jms;

import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
import io.micrometer.observation.transport.ReceiverContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
Expand All @@ -33,12 +34,15 @@
*/
public class JmsProcessObservationContext extends ReceiverContext<Message> {

private static final WarnThenDebugLogger logger = new WarnThenDebugLogger(JmsProcessObservationContext.class);

public JmsProcessObservationContext(Message receivedMessage) {
super((message, key) -> {
try {
return message.getStringProperty(key);
}
catch (JMSException exc) {
catch (JMSException | RuntimeException exc) {
logger.log("Failed get message property.", exc);
return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.micrometer.jakarta9.instrument.jms;

import io.micrometer.common.lang.Nullable;
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
import io.micrometer.observation.transport.SenderContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
Expand All @@ -33,15 +34,17 @@
*/
public class JmsPublishObservationContext extends SenderContext<Message> {

private static final WarnThenDebugLogger logger = new WarnThenDebugLogger(JmsPublishObservationContext.class);

public JmsPublishObservationContext(@Nullable Message sendMessage) {
super((message, key, value) -> {
try {
if (message != null) {
if (message != null) {
try {
message.setStringProperty(key, value);
}
}
catch (JMSException exc) {
// ignore
catch (JMSException | RuntimeException exc) {
logger.log("Failed set message property.", exc);
}
}
});
setCarrier(sendMessage);
Expand Down

0 comments on commit d8fbfc7

Please sign in to comment.