container2.afterPropertiesSet();
container2.start();
assertTrue("wait for start signal", startProducer.await(20, TimeUnit.SECONDS));
final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(
singleConnectionFactory2);
final JmsTemplate template = new JmsTemplate(
cachingConnectionFactory);
final ActiveMQQueue queue = new ActiveMQQueue(
"testingqueue");
for (int i = 0; i < total; i++) {
template.send(queue, new MessageCreator() {
public Message createMessage(
final Session session)
throws JMSException {
final TextMessage message = session
.createTextMessage();
message.setText("Hello World!");
return message;
}
});
}
// give spring time to scale back again
while (container2.getActiveConsumerCount() > 1) {
System.out.println("active consumer count: "
+ container2.getActiveConsumerCount());
System.out.println("concurrent consumer count: "
+ container2.getConcurrentConsumers());
Thread.sleep(1000);
}
cachingConnectionFactory.destroy();
container2.destroy();
} catch (final Throwable t) {
t.printStackTrace();
}
return null;