/** * Receive an ndarray * @return */ public INDArray receive() { if (consumerTemplate == null) consumerTemplate = camelContext.createConsumerTemplate(); return consumerTemplate.receiveBody("direct:receive", INDArray.class); }
@PreDestroy public void stop() throws Exception { try { this.consumer.stop(); } catch (Exception ex) { log.error("Can't stop consumer template", ex); } try { this.producer.stop(); } catch (Exception ex) { log.error("Can't stop producer template", ex); } try { this.ctx.stop(); } catch (Exception ex) { log.error("Can't stop camel context template", ex); } }
@PostConstruct public void start() throws Exception { this.ctx.start(); this.producer.start(); this.consumer.start(); }
receiveBody("hazelcastmq:queue:primo.test", 2000, String.class); consumerTemplate.stop(); camelContext.stop();
@Override @SuppressWarnings("unchecked") public AccurestMessage<T, Message> receiveMessage(String destination, long timeout, TimeUnit timeUnit) { try { ConsumerTemplate consumerTemplate = context.createConsumerTemplate(); Exchange exchange = consumerTemplate.receive(destination, timeUnit.toMillis(timeout)); return builder.create(exchange.getIn()); } catch (Exception e) { log.error("Exception occurred while trying to read a message from " + " a channel with name [" + destination + "]", e); throw new RuntimeException(e); } }
@Override public void send(Message message, TestContext context) { Assert.notNull(message, "Message is empty - unable to send empty message"); String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()); String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context); Exchange exchange = correlationManager.find(correlationKey, endpointConfiguration.getTimeout()); Assert.notNull(exchange, "Failed to find camel exchange for message correlation key: '" + correlationKey + "'"); buildOutMessage(exchange, message); if (log.isDebugEnabled()) { log.debug("Sending reply message to camel endpoint: '" + exchange.getFromEndpoint() + "'"); } getConsumerTemplate().doneUoW(exchange); context.onOutboundMessage(message); log.info("Message was sent to camel endpoint: '" + exchange.getFromEndpoint() + "'"); }
@Override public Message receive(TestContext context, long timeout) { if (log.isDebugEnabled()) { log.debug("Receiving message from camel endpoint: '" + endpointConfiguration.getEndpointUri() + "'"); } Exchange exchange = getConsumerTemplate().receive(endpointConfiguration.getEndpointUri(), timeout); if (exchange == null) { throw new ActionTimeoutException("Action timed out while receiving message from camel endpoint '" + endpointConfiguration.getEndpointUri() + "'"); } log.info("Received message from camel endpoint: '" + endpointConfiguration.getEndpointUri() + "'"); Message message = endpointConfiguration.getMessageConverter().convertInbound(exchange, endpointConfiguration, context); context.onInboundMessage(message); return message; }
public String getOrders() { String order = ""; String orders = ""; while (order != null) { order = consumer.receiveBody("activemq:orders", 1000, String.class); if (order != null) { orders = orders + "," + order; } } return orders; } }
private static void doStopTemplates(ConsumerTemplate consumer, ProducerTemplate template, FluentProducerTemplate fluentTemplate) throws Exception { if (consumer != null) { if (consumer == threadConsumer.get()) { threadConsumer.remove(); } consumer.stop(); } if (template != null) { if (template == threadTemplate.get()) { threadTemplate.remove(); } template.stop(); } if (fluentTemplate != null) { if (fluentTemplate == threadFluentTemplate.get()) { threadFluentTemplate.remove(); } fluentTemplate.stop(); } }
fluentTemplate.start(); consumer = context.createConsumerTemplate(); consumer.start();
@Override public Message receive(TestContext context, long timeout) { if (log.isDebugEnabled()) { log.debug("Receiving message from camel endpoint: '" + endpointConfiguration.getEndpointUri() + "'"); } Exchange exchange = getConsumerTemplate().receive(endpointConfiguration.getEndpointUri(), timeout); if (exchange == null) { throw new ActionTimeoutException("Action timed out while receiving message from camel endpoint '" + endpointConfiguration.getEndpointUri() + "'"); } log.info("Received message from camel endpoint: '" + endpointConfiguration.getEndpointUri() + "'"); Message message = endpointConfiguration.getMessageConverter().convertInbound(exchange, endpointConfiguration, context); context.onInboundMessage(message); String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()); String correlationKey = endpointConfiguration.getCorrelator().getCorrelationKey(message); correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context); correlationManager.store(correlationKey, exchange); return message; }
public static Object receive(final String locator, final String endpoint, final long timeout, final Class<?> expected) { final BeanLocator.LocatorInstance<CamelTemplateLocator> locatorInstance = locator(locator); try { final ConsumerTemplate consumerTemplate = locatorInstance.getValue().findConsumerTemplate(); if (timeout > 0) { if (expected != null) { return consumerTemplate.receiveBody(endpoint, expected); } return consumerTemplate.receiveBody(endpoint); } if (expected != null) { return consumerTemplate.receiveBody(endpoint, timeout, expected); } return consumerTemplate.receiveBody(endpoint, timeout); } finally { locatorInstance.release(); } }
@PreDestroy public void stop() throws Exception { try { this.consumer.stop(); } catch (Exception ex) { log.error("Can't stop consumer template", ex); } try { this.producer.stop(); } catch (Exception ex) { log.error("Can't stop producer template", ex); } try { this.ctx.stop(); } catch (Exception ex) { log.error("Can't stop camel context template", ex); } }
@PostConstruct public void start() throws Exception { this.ctx.start(); this.producer.start(); this.consumer.start(); }
from(URI_WEBSERVICE) .convertBodyTo(Entrada.class) .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { // logic of ProcessorTratarWS goes here ConsumerTemplate consumer=exchange.getContext().createConsumerTemplate(); String filename=exchange.getProperty("archivoRespuesta",String.class); Object file=consumer.receiveBody("ftp://10.100.8.2/entradaCamel?username=USER&password=PASSWORD&delete=true&fileName="+filename,timeOut); // logic of EstrategiaConfirmacion goes here } }) .to(WS_RESPONDER);
public <T> T pollChannel(String channel, Class<T> responseType) { byte[] busResponse = producerTemplate.getCamelContext().createConsumerTemplate().receiveBody("amqp:" + channel, byte[].class); return decodedPayload(busResponse, responseType); }
List data = (List<Person>)ct.receiveBody("seda:foo", 5000);