private void createCamelContext() throws Exception { log.info("creating context and sending message"); camelContext = new DefaultCamelContext(); camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(BROKER_URL)); final String queueEndpointName = "activemq:queue" + QUEUE_NAME; camelContext.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { from(queueEndpointName).bean(Consumer.class, "consume"); } }); camelContext.start(); final ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); producerTemplate.sendBody(queueEndpointName, "message"); }
public void pollCurrentLog() { try { CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent( "jms", org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent( "tcp://localhost:61616")); ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(); Message message = consumerTemplate.receive("jms:queue:maven-logs").getIn(); if (message != null && message.getBody() != null) { if (currentLog == null) { currentLog = message.getBody().toString(); } else { currentLog += "\n" + message.getBody(); } } } catch (Exception e) { logger.error("Error:", e); } }