21
21
import java .util .concurrent .atomic .AtomicReference ;
22
22
import java .util .stream .Stream ;
23
23
24
+ import io .micrometer .jakarta9 .instrument .jms .JmsProcessObservationContext ;
24
25
import io .micrometer .observation .Observation ;
26
+ import io .micrometer .observation .ObservationHandler ;
25
27
import io .micrometer .observation .tck .TestObservationRegistry ;
26
28
import jakarta .jms .MessageListener ;
27
29
import org .apache .activemq .artemis .jms .client .ActiveMQConnectionFactory ;
@@ -117,14 +119,14 @@ void shouldHaveObservationErrorWhenRethrown(AbstractMessageListenerContainer lis
117
119
JmsTemplate jmsTemplate = new JmsTemplate (connectionFactory );
118
120
jmsTemplate .convertAndSend ("spring.test.observation" , "message content" );
119
121
CountDownLatch latch = new CountDownLatch (1 );
122
+ registry .observationConfig ().observationHandler (new ErrorHandlerObservationHandler (latch ));
120
123
listenerContainer .setConnectionFactory (connectionFactory );
121
124
listenerContainer .setObservationRegistry (registry );
122
125
listenerContainer .setDestinationName ("spring.test.observation" );
123
126
listenerContainer .setMessageListener ((MessageListener ) message -> {
124
127
throw new IllegalStateException ("error" );
125
128
});
126
129
listenerContainer .setErrorHandler (error -> {
127
- latch .countDown ();
128
130
throw new IllegalStateException ("not handled" );
129
131
});
130
132
listenerContainer .afterPropertiesSet ();
@@ -139,6 +141,25 @@ void shouldHaveObservationErrorWhenRethrown(AbstractMessageListenerContainer lis
139
141
listenerContainer .shutdown ();
140
142
}
141
143
144
+ static class ErrorHandlerObservationHandler implements ObservationHandler <JmsProcessObservationContext > {
145
+
146
+ private final CountDownLatch latch ;
147
+
148
+ ErrorHandlerObservationHandler (CountDownLatch latch ) {
149
+ this .latch = latch ;
150
+ }
151
+
152
+ @ Override
153
+ public boolean supportsContext (Observation .Context context ) {
154
+ return context instanceof JmsProcessObservationContext ;
155
+ }
156
+
157
+ @ Override
158
+ public void onError (JmsProcessObservationContext context ) {
159
+ this .latch .countDown ();
160
+ }
161
+ }
162
+
142
163
static Stream <Arguments > listenerContainers () {
143
164
return Stream .of (
144
165
arguments (named (DefaultMessageListenerContainer .class .getSimpleName (), new DefaultMessageListenerContainer ())),
0 commit comments