/** * Receive an ndarray * @return */ public INDArray receive() { if (consumerTemplate == null) consumerTemplate = camelContext.createConsumerTemplate(); return consumerTemplate.receiveBody("direct:receive", INDArray.class); }
/** * Get's the {@link ConsumerTemplate} to be used. */ @Bean(initMethod = "", destroyMethod = "") // Camel handles the lifecycle of this bean public ConsumerTemplate consumerTemplate(CamelContext camelContext) throws Exception { return camelContext.createConsumerTemplate(); }
@Produces // Qualifiers are dynamically added in CdiCamelExtension private static ConsumerTemplate consumerTemplate(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { return selectContext(ip, instance, extension).createConsumerTemplate(); }
/** * Creates new consumer template if not present yet. Create consumer template only once which is * mandatory for direct endpoints that do only support one single consumer at a time. * @return */ protected ConsumerTemplate getConsumerTemplate() { if (consumerTemplate == null) { consumerTemplate = endpointConfiguration.getCamelContext().createConsumerTemplate(); } return consumerTemplate; }
/** * Default consumer template for the bootstrapped Camel context. */ @Bean ConsumerTemplate consumerTemplate() throws Exception { return camelContext().createConsumerTemplate(); }
@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); } }
/** * Default consumer template for the bootstrapped Camel context. * Create the bean lazy as it should only be created if its in-use. */ // We explicitly declare the destroyMethod to be "" as the Spring @Bean // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise // and in that case Service::close (ConsumerTemplate implements Service) // would be used for bean destruction. And we want Camel to handle the // lifecycle. @Bean(destroyMethod = "") @ConditionalOnMissingBean(ConsumerTemplate.class) @Lazy ConsumerTemplate consumerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception { final ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize()); // we add this consumerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop) camelContext.addService(consumerTemplate); return consumerTemplate; }
camelContext.start(); producerTemplate = camelContext.createProducerTemplate(); consumerTemplate = camelContext.createConsumerTemplate(); log.debug("Bundle {} started.", bundleContext.getBundle().getBundleId()); } catch (Throwable e) {
public <T> T pollChannel(String channel, Class<T> responseType) { byte[] busResponse = producerTemplate.getCamelContext().createConsumerTemplate().receiveBody("amqp:" + channel, byte[].class); return decodedPayload(busResponse, responseType); }
@Override public Set<Object> lookupMicroservice(final MicroserviceMetaData metaData) { if (Route.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.getRoute(metaData.getName())); } else if (Endpoint.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.getEndpoint(metaData.getName())); } else if (TypeConverter.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.getTypeConverter()); } else if (Component.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.getComponent(metaData.getName())); } else if (ConsumerTemplate.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.createConsumerTemplate()); } else if (ProducerTemplate.class.isAssignableFrom(metaData.getType())) { return Collections.singleton(camelContext.createProducerTemplate()); } return new HashSet<>(); }
producer.sendBody("done"); consumer = context.createConsumerTemplate(); String body = null; while (!"done".equals(body)) {
ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(); String body = consumerTemplate. receiveBody("hazelcastmq:queue:primo.test", 2000, String.class);