Search in sources :

Example 1 with MessageConsumer

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);
    }
}
Also used : ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Heartbeat(org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat) Test(org.junit.Test)

Example 2 with MessageConsumer

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);
    }
}
Also used : MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.aws.sqs.heartbeat.HeartbeatModule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Heartbeat(org.opennms.core.ipc.sink.aws.sqs.heartbeat.Heartbeat) Test(org.junit.Test)

Example 3 with MessageConsumer

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);
}
Also used : ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 4 with MessageConsumer

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);
}
Also used : MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) CountDownLatch(java.util.concurrent.CountDownLatch) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Aggregations

Test (org.junit.Test)4 MessageConsumer (org.opennms.core.ipc.sink.api.MessageConsumer)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MessageDispatcherFactory (org.opennms.core.ipc.sink.api.MessageDispatcherFactory)2 Heartbeat (org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat)2 HeartbeatModule (org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule)2 ThreadLockingMessageConsumer (org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer)2 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Heartbeat (org.opennms.core.ipc.sink.aws.sqs.heartbeat.Heartbeat)1 HeartbeatModule (org.opennms.core.ipc.sink.aws.sqs.heartbeat.HeartbeatModule)1 Heartbeat (org.opennms.core.ipc.sink.kafka.heartbeat.Heartbeat)1 HeartbeatModule (org.opennms.core.ipc.sink.kafka.heartbeat.HeartbeatModule)1