use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testConcurrentMessageConsumption.
@Test
public void testConcurrentMessageConsumption() throws InterruptedException {
IDestination<Object> queue = MOM.newDestination("test/mom/testConcurrentMessageConsumption", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
// 1. Publish some messages
int msgCount = 10;
for (int i = 0; i < msgCount; i++) {
MOM.publish(JmsTestMom.class, queue, "hello");
}
// 1. Publish some messages
final BlockingCountDownLatch latch = new BlockingCountDownLatch(msgCount, 3, TimeUnit.SECONDS);
m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<Object>() {
@Override
public void onMessage(IMessage<Object> message) {
try {
// timeout must be greater than the default latch timeout
latch.countDownAndBlock(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
throw BEANS.get(DefaultRuntimeExceptionTranslator.class).translate(e);
}
}
}));
try {
assertTrue("messages expected to be consumed concurrently", latch.await());
} finally {
latch.unblock();
}
}
Aggregations