Search in sources :

Example 1 with JmsQueueNameFactory

use of org.opennms.core.camel.JmsQueueNameFactory in project opennms by OpenNMS.

the class CamelRpcClientPreProcessor method process.

@Override
public void process(Exchange exchange) {
    @SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest, RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class);
    final JmsQueueNameFactory queueNameFactory = new JmsQueueNameFactory(CamelRpcConstants.JMS_QUEUE_PREFIX, wrapper.getModule().getId(), wrapper.getRequest().getLocation());
    exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, queueNameFactory.getName());
    exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT);
    final String request = wrapper.getModule().marshalRequest((RpcRequest) wrapper.getRequest());
    exchange.getIn().setBody(request);
}
Also used : RpcRequest(org.opennms.core.rpc.api.RpcRequest) RpcResponse(org.opennms.core.rpc.api.RpcResponse) JmsQueueNameFactory(org.opennms.core.camel.JmsQueueNameFactory)

Example 2 with JmsQueueNameFactory

use of org.opennms.core.camel.JmsQueueNameFactory in project opennms by OpenNMS.

the class CamelRemoteMessageDispatcherFactory method getModuleMetadata.

public <S extends Message, T extends Message> Map<String, Object> getModuleMetadata(SinkModule<S, T> module) {
    // Pre-compute the JMS headers instead of recomputing them every dispatch
    final JmsQueueNameFactory queueNameFactory = new JmsQueueNameFactory(CamelSinkConstants.JMS_QUEUE_PREFIX, module.getId());
    Map<String, Object> headers = new HashMap<>();
    headers.put(CamelSinkConstants.JMS_QUEUE_NAME_HEADER, queueNameFactory.getName());
    return Collections.unmodifiableMap(headers);
}
Also used : HashMap(java.util.HashMap) JmsQueueNameFactory(org.opennms.core.camel.JmsQueueNameFactory)

Example 3 with JmsQueueNameFactory

use of org.opennms.core.camel.JmsQueueNameFactory in project opennms by OpenNMS.

the class PollerRpcTimeoutIT method testPolling.

@Test
public void testPolling() throws Exception {
    String queueName = new JmsQueueNameFactory("RPC", "Poller", NONEXISTENT_LOCATION).getName();
    try {
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ"));
        fail("DLQ was unexpected found in the PlatformMBeanServer");
    } catch (InstanceNotFoundException e) {
    // Expected: the queue hasn't been created yet
    }
    try {
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queueName));
        fail(queueName + " queue was unexpected found in the PlatformMBeanServer");
    } catch (InstanceNotFoundException e) {
    // Expected: the queue hasn't been created yet
    }
    // Start the poller: polls will timeout because there is no consumer for the location
    startDaemons();
    // Sleep long enough so that messages would be flushed to the DLQ
    Thread.sleep(60000);
    // Stop the poller daemon
    stopDaemons();
    try {
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ"));
        fail("DLQ was unexpected found in the PlatformMBeanServer");
    } catch (InstanceNotFoundException e) {
    // Expected: the DLQ still should be absent
    }
    Long dequeueCount = (Long) ManagementFactory.getPlatformMBeanServer().getAttribute(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queueName), "DequeueCount");
    Long expiredCount = (Long) ManagementFactory.getPlatformMBeanServer().getAttribute(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queueName), "ExpiredCount");
    Long dispatchCount = (Long) ManagementFactory.getPlatformMBeanServer().getAttribute(ObjectName.getInstance("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queueName), "DispatchCount");
    assertTrue("No expired messages were present", expiredCount > 0L);
    assertEquals("Dequeued messages do not equal expired messages", expiredCount, dequeueCount);
    assertEquals("Dispatched message count was not zero", 0, dispatchCount.intValue());
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) JmsQueueNameFactory(org.opennms.core.camel.JmsQueueNameFactory) Test(org.junit.Test)

Aggregations

JmsQueueNameFactory (org.opennms.core.camel.JmsQueueNameFactory)3 HashMap (java.util.HashMap)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 Test (org.junit.Test)1 RpcRequest (org.opennms.core.rpc.api.RpcRequest)1 RpcResponse (org.opennms.core.rpc.api.RpcResponse)1