/** * Publish to a kafka topic * based on the connection information * @param arr */ public void publish(INDArray arr) { if (producerTemplate == null) producerTemplate = camelContext.createProducerTemplate(); producerTemplate.sendBody("direct:start", arr); }
protected ProducerTemplate findOrCreateCamelTemplate() { String[] names = getApplicationContext().getBeanNamesForType(ProducerTemplate.class); if (names != null && names.length > 0) { return getApplicationContext().getBean(names[0], ProducerTemplate.class); } if (getCamelContexts().isEmpty()) { throw new IllegalArgumentException("No CamelContexts are available so cannot create a ProducerTemplate!"); } return getCamelContexts().get(0).createProducerTemplate(); }
/** * Get's the {@link ProducerTemplate} to be used. */ @Bean(initMethod = "", destroyMethod = "") // Camel handles the lifecycle of this bean public ProducerTemplate producerTemplate(CamelContext camelContext) throws Exception { return camelContext.createProducerTemplate(); }
/** * Creates new producer template if not present yet. Create producer template only once which is * mandatory for direct endpoints that do only support one single producer at a time. * @return */ protected ProducerTemplate getProducerTemplate() { if (producerTemplate == null) { producerTemplate = endpointConfiguration.getCamelContext().createProducerTemplate(); } return producerTemplate; }
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { PrintWriter out = res.getWriter(); String msg = req.getParameter("test"); ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", msg, String.class); out.print(result); out.close(); } }
@Bean public ProducerTemplate bundleRefresh() throws Exception { final ProducerTemplate template = camelContext.createProducerTemplate(); template.setDefaultEndpointUri(refreshEndpoint); return template; }
private static ProducerTemplate defaultProducerTemplate(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { try { CamelContext context = selectContext(ip, instance, extension); return context.createProducerTemplate(); } catch (Exception cause) { throw new InjectionException("Error injecting producer template into " + ip, cause); } }
CamelContext context = new DefaultCamelContext(); CxfComponent cxfComponent = new CxfComponent(context); CxfEndpoint serviceEndpoint = new CxfEndpoint("http://www.webservicex.net/stockquote.asmx", cxfComponent); // Service class generated by CXF codegen plugin. serviceEndpoint.setServiceClass(StockQuoteSoap.class); ProducerTemplate template = context.createProducerTemplate(); // Request and response can be 'bare' or 'wrapped', see the service class. String getQuoteResponse = template.requestBody(serviceEndpoint, "MSFT", String.class); System.out.println(getQuoteResponse);
public ProducerTemplate getCamelTemplate() throws Exception { if (camelTemplate == null) { CamelContext ctx = getCamelContext(); if (ctx == null) { // TODO: This doesnt look good to create a new CamelContext out of the blue ctx = new DefaultCamelContext(); } camelTemplate = ctx.createProducerTemplate(); } return camelTemplate; }
@Override protected ProducerTemplate findOrCreateCamelTemplate() { return getReferenceByType(cdiContainer.getBeanManager(), CamelContext.class) .orElseThrow( () -> new UnsatisfiedResolutionException("No default Camel context is deployed, " + "cannot create default ProducerTemplate!")) .createProducerTemplate(); }
@Override @PostConstruct public void init() throws Exception { producerTemplate = context.createProducerTemplate(); if (context.getStatus().isStopped()) { context.start(); } super.init(); }
@Test public void testRequest() { assertThat(context.getBean("my-bean", MyBean.class)).isNotNull(); final ProducerTemplate template = camelContext.createProducerTemplate(); final String body = "hello"; final String result = template.requestBody("direct:start", body, String.class); final String expected = Base64.getEncoder().encodeToString("HELLO WORLD!".toUpperCase().getBytes(StandardCharsets.US_ASCII)); assertThat(result).isEqualTo(expected); }
@Test public void testRequest() { assertThat(context.getBean("my-bean", MyBean.class)).isNotNull(); final ProducerTemplate template = camelContext.createProducerTemplate(); final String body = "hello"; final String result = template.requestBody("direct:start", body, String.class); final String expected = "HEY, HELLO WORLD!"; assertThat(result).isEqualTo(expected); }
@Test public void testRequest() { assertThat(context.getBean("my-bean", MyBean.class)).isNotNull(); final ProducerTemplate template = camelContext.createProducerTemplate(); final String body = "hello"; final String result = template.requestBody("direct:start", body, String.class); final String expected = "HELLO"; assertThat(result).isEqualTo(expected); }
/** camel context startup and template creation */ private void initializeTemplate(KieSession session) throws Exception { CamelContext context = configure(session); this.template = context.createProducerTemplate(); context.start(); }
/** camel context startup and template creation */ private void initializeTemplate(KieSession session) throws Exception { CamelContext context = configure(session); this.template = context.createProducerTemplate(); context.start(); }
/** * camel context startup and template creation */ private void initializeTemplate(StatefulKnowledgeSession session) throws Exception { CamelContext context = configure(session); this.template = context.createProducerTemplate(); context.start(); }
/** * camel context startup and template creation */ private void initializeTemplate(StatefulKnowledgeSession session) throws Exception { CamelContext context = configure(session); this.template = context.createProducerTemplate(); context.start(); }
@Test public void testSend() throws Exception { assertThat(context.getBean("my-bean", MyBean.class)).isNotNull(); final ProducerTemplate template = camelContext.createProducerTemplate(); final MockEndpoint mock = camelContext.getEndpoint("mock:result", MockEndpoint.class); final String body = "hello"; final String expected = Base64.getEncoder().encodeToString("HELLO WORLD!".toUpperCase().getBytes(StandardCharsets.US_ASCII)); mock.expectedMessageCount(1); mock.expectedBodiesReceived(expected); template.sendBody("direct:start", body); mock.assertIsSatisfied(); }
@Test public void testSend() throws Exception { assertThat(context.getBean("my-bean", MyBean.class)).isNotNull(); final ProducerTemplate template = camelContext.createProducerTemplate(); final MockEndpoint mock = camelContext.getEndpoint("mock:result", MockEndpoint.class); final String body = "hello"; final String expected = "HEY, HELLO WORLD!"; mock.expectedMessageCount(1); mock.expectedBodiesReceived(expected); template.sendBody("direct:start", body); mock.assertIsSatisfied(); }