use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testTopicPublishFirst.
@Test
// regression
@Times(10)
public void testTopicPublishFirst() throws InterruptedException {
IDestination<String> topic = MOM.newDestination("test/mom/testTopicPublishFirst", DestinationType.TOPIC, ResolveMethod.DEFINE, null);
// Publish a message
MOM.publish(JmsTestMom.class, topic, "hello world");
// Subscribe for the destination
final CountDownLatch latch = new CountDownLatch(1);
m_disposables.add(MOM.subscribe(JmsTestMom.class, topic, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
latch.countDown();
}
}));
// Verify
assertFalse(latch.await(200, TimeUnit.MILLISECONDS));
}
use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testMomEnvironmentWithCustomDefaultMarshaller.
@Test
public void testMomEnvironmentWithCustomDefaultMarshaller() throws InterruptedException {
installTestMom(JmsTestMomWithTextMarshaller.class);
final Capturer<String> capturer1 = new Capturer<>();
final Capturer<Object> capturer2 = new Capturer<>();
IDestination<String> queueString = MOM.newDestination("test/mom/testPublishStringData", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
IDestination<Object> queueObject = MOM.newDestination("test/mom/testPublishObjectData", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
m_disposables.add(MOM.registerMarshaller(JmsTestMom.class, queueObject, BEANS.get(ObjectMarshaller.class)));
MOM.publish(JmsTestMom.class, queueString, "Hello MOM!");
MOM.publish(JmsTestMom.class, queueObject, new StringHolder("Hello MOM! (holder)"));
m_disposables.add(MOM.subscribe(JmsTestMom.class, queueString, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
capturer1.set(message.getTransferObject());
}
}));
m_disposables.add(MOM.subscribe(JmsTestMom.class, queueObject, new IMessageListener<Object>() {
@Override
public void onMessage(IMessage<Object> message) {
capturer2.set(message.getTransferObject());
}
}));
// Verify
String received1 = capturer1.get();
Object received2 = capturer2.get();
assertEquals("Hello MOM!", received1);
assertEquals("Hello MOM! (holder)", Objects.toString(received2));
}
use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testPublishSubscribeCorrelationIdInternal.
private void testPublishSubscribeCorrelationIdInternal(final IDestination<String> destination) throws InterruptedException {
final Capturer<String> cid = new Capturer<>();
m_disposables.add(MOM.subscribe(JmsTestMom.class, destination, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
cid.set(CorrelationId.CURRENT.get());
}
}, MOM.newSubscribeInput().withRunContext(RunContexts.copyCurrent().withCorrelationId("cid:xyz"))));
RunContexts.copyCurrent().withCorrelationId("cid:abc").run(new IRunnable() {
@Override
public void run() throws Exception {
MOM.publish(JmsTestMom.class, destination, "hello world");
}
});
assertEquals("cid:abc", cid.get());
}
use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testRequestReplyCorrelationIdInternal.
private void testRequestReplyCorrelationIdInternal(final IBiDestination<String, String> destination) throws InterruptedException {
m_disposables.add(MOM.reply(JmsTestMom.class, destination, new IRequestListener<String, String>() {
@Override
public String onRequest(IMessage<String> request) {
return CorrelationId.CURRENT.get();
}
}, MOM.newSubscribeInput().withRunContext(RunContexts.copyCurrent().withCorrelationId("cid:xyz"))));
// Initiate 'request-reply' communication
RunContexts.empty().withCorrelationId("cid:abc").run(new IRunnable() {
@Override
public void run() throws Exception {
String testee = MOM.request(JmsTestMom.class, destination, "hello world");
// Verify
assertEquals("cid:abc", testee);
}
});
}
use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.
the class JmsMomImplementorTest method testTopicPublishSubscribeMultipleSubscriptions.
@Test
public void testTopicPublishSubscribeMultipleSubscriptions() throws InterruptedException {
IDestination<String> topic = MOM.newDestination("test/mom/testTopicPublishSubscribeMultipleSubscriptions", DestinationType.TOPIC, ResolveMethod.DEFINE, null);
final CountDownLatch latch = new CountDownLatch(2);
// Subscribe for the destination
m_disposables.add(MOM.subscribe(JmsTestMom.class, topic, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
latch.countDown();
}
}));
// Subscribe for the destination
m_disposables.add(MOM.subscribe(JmsTestMom.class, topic, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
latch.countDown();
}
}));
// Publish a message
MOM.publish(JmsTestMom.class, topic, "hello world");
// Verify
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Aggregations