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);
}
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);
}
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());
}
Aggregations