use of org.apache.ignite.IgniteMessaging in project camel by apache.
the class IgniteMessagingEndpoint method createIgniteMessaging.
private IgniteMessaging createIgniteMessaging() {
Ignite ignite = ignite();
IgniteMessaging messaging = clusterGroupExpression == null ? ignite.message() : ignite.message(clusterGroupExpression.getClusterGroup(ignite));
return messaging;
}
use of org.apache.ignite.IgniteMessaging in project camel by apache.
the class IgniteMessagingEndpoint method createConsumer.
@Override
public Consumer createConsumer(Processor processor) throws Exception {
// Validate options.
if (topic == null) {
throw new IllegalStateException("Cannot initialize an Ignite Messaging Consumer with a null topic.");
}
// Initialize the Consumer.
IgniteMessaging messaging = createIgniteMessaging();
IgniteMessagingConsumer consumer = new IgniteMessagingConsumer(this, processor, messaging);
configureConsumer(consumer);
return consumer;
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class MessagingSandboxTest method execute.
/**
*/
private void execute(Ignite node, BiFunction<IgniteMessaging, String, UUID> func, boolean isForbiddenCase) {
final String topic = "test_topic";
IgniteMessaging messaging = node.message(node.cluster().forNodeId(grid(SRV).localNode().id()));
UUID listenerId = func.apply(messaging, topic);
try {
GridTestUtils.RunnableX r = () -> {
error = null;
latch = new CountDownLatch(1);
grid(SRV_SENDER).message().send(topic, "Hello!");
latch.await(10, TimeUnit.SECONDS);
if (error != null)
throw error;
};
if (isForbiddenCase)
runForbiddenOperation(r, AccessControlException.class);
else
runOperation(r);
} finally {
messaging.stopRemoteListen(listenerId);
}
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class MessagingRemoteSecurityContextCheckTest method execute.
/**
*/
private void execute(BiFunction<IgniteMessaging, String, UUID> func) {
runAndCheck(() -> {
Ignite loc = Ignition.localIgnite();
IgniteMessaging messaging = loc.message(loc.cluster().forNodeIds(nodesToCheckIds()));
Integer idx = TOPIC_INDEX.incrementAndGet();
String topic = "test_topic_" + idx;
UUID id = func.apply(messaging, topic);
try {
grid(SRV).message().send(topic, idx);
wait(idx);
} finally {
messaging.stopRemoteListen(id);
}
});
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class GridMessagingSelfTest method testAsyncOld.
/**
* @throws Exception If failed.
*/
@Test
public void testAsyncOld() throws Exception {
final AtomicInteger msgCnt = new AtomicInteger();
IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
discoSpi.setInternalListener(lsnr);
assertFalse(ignite2.message().isAsync());
final IgniteMessaging msg = ignite2.message().withAsync();
assertTrue(msg.isAsync());
assertFalse(ignite2.message().isAsync());
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
final String topic = "topic";
UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt.incrementAndGet();
return true;
}
});
Assert.assertNull(id);
IgniteFuture<UUID> starFut = msg.future();
Assert.assertNotNull(starFut);
U.sleep(500);
Assert.assertFalse(starFut.isDone());
lsnr.stopBlockCustomEvents();
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
id = starFut.get();
Assert.assertNotNull(id);
Assert.assertTrue(starFut.isDone());
lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
message(ignite1.cluster().forRemotes()).send(topic, "msg1");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt.get());
msg.stopRemoteListen(id);
IgniteFuture<?> stopFut = msg.future();
Assert.assertNotNull(stopFut);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
U.sleep(500);
Assert.assertFalse(stopFut.isDone());
lsnr.stopBlockCustomEvents();
stopFut.get();
Assert.assertTrue(stopFut.isDone());
message(ignite1.cluster().forRemotes()).send(topic, "msg2");
U.sleep(1000);
assertEquals(1, msgCnt.get());
}
Aggregations