23
23
import java .util .UUID ;
24
24
25
25
import javax .jms .ConnectionFactory ;
26
- import javax .jms .Destination ;
27
- import javax .jms .JMSException ;
28
26
import javax .jms .Message ;
29
27
import javax .jms .TextMessage ;
30
28
29
+ import org .apache .activemq .artemis .api .core .RoutingType ;
30
+ import org .apache .activemq .artemis .api .core .SimpleString ;
31
31
import org .apache .activemq .artemis .api .core .TransportConfiguration ;
32
32
import org .apache .activemq .artemis .core .remoting .impl .invm .InVMConnectorFactory ;
33
33
import org .apache .activemq .artemis .core .remoting .impl .netty .NettyConnectorFactory ;
34
+ import org .apache .activemq .artemis .core .server .BindingQueryResult ;
34
35
import org .apache .activemq .artemis .jms .client .ActiveMQConnectionFactory ;
35
36
import org .apache .activemq .artemis .jms .server .config .JMSConfiguration ;
36
37
import org .apache .activemq .artemis .jms .server .config .JMSQueueConfiguration ;
51
52
import org .springframework .context .annotation .Configuration ;
52
53
import org .springframework .jms .connection .CachingConnectionFactory ;
53
54
import org .springframework .jms .core .JmsTemplate ;
54
- import org .springframework .jms .core .SessionCallback ;
55
- import org .springframework .jms .support .destination .DestinationResolver ;
56
- import org .springframework .jms .support .destination .DynamicDestinationResolver ;
57
55
58
56
import static org .assertj .core .api .Assertions .assertThat ;
59
57
@@ -206,9 +204,9 @@ void embeddedServerWithDestinations() {
206
204
DestinationChecker checker = new DestinationChecker (context );
207
205
checker .checkQueue ("Queue1" , true );
208
206
checker .checkQueue ("Queue2" , true );
209
- checker .checkQueue ("QueueWillNotBeAutoCreated " , true );
207
+ checker .checkQueue ("NonExistentQueue " , false );
210
208
checker .checkTopic ("Topic1" , true );
211
- checker .checkTopic ("TopicWillBeAutoCreated " , true );
209
+ checker .checkTopic ("NonExistentTopic " , false );
212
210
});
213
211
}
214
212
@@ -228,8 +226,8 @@ void embeddedServiceWithCustomJmsConfiguration() {
228
226
.withPropertyValues ("spring.artemis.embedded.queues=Queue1,Queue2" ).run ((context ) -> {
229
227
DestinationChecker checker = new DestinationChecker (context );
230
228
checker .checkQueue ("custom" , true ); // See CustomJmsConfiguration
231
- checker .checkQueue ("Queue1" , true );
232
- checker .checkQueue ("Queue2" , true );
229
+ checker .checkQueue ("Queue1" , false );
230
+ checker .checkQueue ("Queue2" , false );
233
231
});
234
232
}
235
233
@@ -273,10 +271,10 @@ void severalEmbeddedBrokers() {
273
271
.isLessThan (secondProperties .getEmbedded ().getServerId ());
274
272
DestinationChecker firstChecker = new DestinationChecker (first );
275
273
firstChecker .checkQueue ("Queue1" , true );
276
- firstChecker .checkQueue ("Queue2" , true );
274
+ firstChecker .checkQueue ("Queue2" , false );
277
275
DestinationChecker secondChecker = new DestinationChecker (second );
276
+ secondChecker .checkQueue ("Queue1" , false );
278
277
secondChecker .checkQueue ("Queue2" , true );
279
- secondChecker .checkQueue ("Queue1" , true );
280
278
});
281
279
});
282
280
}
@@ -293,10 +291,9 @@ void connectToASpecificEmbeddedBroker() {
293
291
// Do not start a specific one
294
292
"spring.artemis.embedded.enabled=false" )
295
293
.run ((secondContext ) -> {
296
- DestinationChecker firstChecker = new DestinationChecker (first );
297
- firstChecker .checkQueue ("Queue1" , true );
298
- DestinationChecker secondChecker = new DestinationChecker (secondContext );
299
- secondChecker .checkQueue ("Queue1" , true );
294
+ first .getBean (JmsTemplate .class ).convertAndSend ("Queue1" , "test" );
295
+ assertThat (secondContext .getBean (JmsTemplate .class ).receiveAndConvert ("Queue1" ))
296
+ .isEqualTo ("test" );
300
297
});
301
298
});
302
299
}
@@ -382,40 +379,31 @@ private TransportConfiguration getSingleTransportConfiguration(ActiveMQConnectio
382
379
383
380
private static final class DestinationChecker {
384
381
385
- private final JmsTemplate jmsTemplate ;
386
-
387
- private final DestinationResolver destinationResolver ;
382
+ private final EmbeddedJMS embeddedJms ;
388
383
389
384
private DestinationChecker (ApplicationContext applicationContext ) {
390
- this .jmsTemplate = applicationContext .getBean (JmsTemplate .class );
391
- this .destinationResolver = new DynamicDestinationResolver ();
385
+ this .embeddedJms = applicationContext .getBean (EmbeddedJMS .class );
392
386
}
393
387
394
388
void checkQueue (String name , boolean shouldExist ) {
395
- checkDestination (name , false , shouldExist );
389
+ checkDestination (name , RoutingType . ANYCAST , shouldExist );
396
390
}
397
391
398
392
void checkTopic (String name , boolean shouldExist ) {
399
- checkDestination (name , true , shouldExist );
393
+ checkDestination (name , RoutingType . MULTICAST , shouldExist );
400
394
}
401
395
402
- void checkDestination (String name , final boolean pubSub , final boolean shouldExist ) {
403
- this .jmsTemplate .execute ((SessionCallback <Void >) (session ) -> {
404
- try {
405
- Destination destination = this .destinationResolver .resolveDestinationName (session , name , pubSub );
406
- if (!shouldExist ) {
407
- throw new IllegalStateException (
408
- "Destination '" + name + "' was not expected but got " + destination );
409
- }
410
- }
411
- catch (JMSException ex ) {
412
- if (shouldExist ) {
413
- throw new IllegalStateException (
414
- "Destination '" + name + "' was expected but got " + ex .getMessage ());
415
- }
396
+ void checkDestination (String name , RoutingType routingType , boolean shouldExist ) {
397
+ try {
398
+ BindingQueryResult result = this .embeddedJms .getActiveMQServer ().bindingQuery (new SimpleString (name ));
399
+ assertThat (result .isExists ()).isEqualTo (shouldExist );
400
+ if (shouldExist ) {
401
+ assertThat (result .getAddressInfo ().getRoutingType ()).isEqualTo (routingType );
416
402
}
417
- return null ;
418
- });
403
+ }
404
+ catch (Exception ex ) {
405
+ throw new RuntimeException (ex );
406
+ }
419
407
}
420
408
421
409
}
0 commit comments