use of org.opennms.core.ipc.sink.api.MessageConsumer in project opennms by OpenNMS.
the class HeartbeatSinkIT method canProduceAndConsumeMessages.
@Test(timeout = 30000)
public void canProduceAndConsumeMessages() throws Exception {
HeartbeatModule module = new HeartbeatModule();
AtomicInteger heartbeatCount = new AtomicInteger();
final MessageConsumer<Heartbeat, Heartbeat> heartbeatConsumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(final Heartbeat heartbeat) {
heartbeatCount.incrementAndGet();
}
};
try {
consumerManager.registerConsumer(heartbeatConsumer);
final SyncDispatcher<Heartbeat> localDispatcher = localMessageDispatcherFactory.createSyncDispatcher(module);
localDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(1));
final SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
dispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(2));
} finally {
consumerManager.unregisterConsumer(heartbeatConsumer);
}
}
use of org.opennms.core.ipc.sink.api.MessageConsumer in project opennms by OpenNMS.
the class HeartbeatSinkIT method canProduceAndConsumeMessages.
/**
* Can produce and consume messages.
*
* @throws Exception the exception
*/
@Test(timeout = 30000)
public void canProduceAndConsumeMessages() throws Exception {
HeartbeatModule module = new HeartbeatModule();
AtomicInteger heartbeatCount = new AtomicInteger();
final MessageConsumer<Heartbeat, Heartbeat> heartbeatConsumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(final Heartbeat heartbeat) {
heartbeatCount.incrementAndGet();
}
};
try {
consumerManager.registerConsumer(heartbeatConsumer);
final SyncDispatcher<Heartbeat> localDispatcher = localMessageDispatcherFactory.createSyncDispatcher(module);
localDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(1));
final SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
dispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(2));
} finally {
consumerManager.unregisterConsumer(heartbeatConsumer);
}
}
use of org.opennms.core.ipc.sink.api.MessageConsumer in project opennms by OpenNMS.
the class HeartbeatSinkBlueprintIT method canProduceAndConsumerMessages.
@Test(timeout = 60000)
public void canProduceAndConsumerMessages() throws Exception {
HeartbeatModule module = new HeartbeatModule();
AtomicInteger heartbeatCount = new AtomicInteger();
MessageConsumer<Heartbeat, Heartbeat> consumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(Heartbeat heartbeat) {
heartbeatCount.incrementAndGet();
}
};
consumerManager.registerConsumer(consumer);
SyncDispatcher<Heartbeat> localDispatcher = localMessageDispatcherFactory.createSyncDispatcher(module);
localDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(1));
MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
SyncDispatcher<Heartbeat> remoteDispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(module);
remoteDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(2));
consumerManager.unregisterConsumer(consumer);
}
use of org.opennms.core.ipc.sink.api.MessageConsumer in project opennms by OpenNMS.
the class SinkBlueprintMessageFailureIT method doesntLogMessageBody.
@Test(timeout = 60000)
public void doesntLogMessageBody() throws Exception {
HeartbeatModule module = new HeartbeatModule();
final CountDownLatch consumed = new CountDownLatch(1);
// Create a consumer that just throws exceptions during the exchange
MessageConsumer<Heartbeat, Heartbeat> consumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(Heartbeat heartbeat) {
consumed.countDown();
throw new IllegalStateException();
}
};
consumerManager.registerConsumer(consumer);
// Fetch the remote dispatcher from the blueprint context
MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
dispatcher.send(new Heartbeat());
consumed.await();
// Sleep slightly longer to allow the body to be logged on the sink consumer listener thread
Thread.sleep(2000);
// Verify that the exchange error was logged
MockLogAppender.assertLogMatched(Level.ERROR, "Message History");
MockLogAppender.assertLogMatched(Level.ERROR, "queuingservice://OpenNMS.Sink.Heartbeat");
// Verify that the message body was suppressed
MockLogAppender.assertNoLogMatched(Level.ERROR, "<heartbeat/>");
consumerManager.unregisterConsumer(consumer);
}
Aggregations