Refine search
/** * 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); }
/** * Sends a message to the given endpoint URI with the body value * * @param endpointUri the URI of the endpoint to send to * @param body the body for the message */ protected void sendBody(String endpointUri, final Object body) { template.send(endpointUri, new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(body); } }); }
@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); } }
@Test public void testListContainers() throws Exception { MockEndpoint mockEndpoint = getMockEndpoint( "mock:result" ); mockEndpoint.expectedMessageCount( 1 ); Map<String, Object> headers = new HashMap<>(); headers.put(KIE_CLIENT, "kieServices"); headers.put(KIE_OPERATION, "listContainers"); template.sendBodyAndHeaders("direct:start", null, headers); assertMockEndpointsSatisfied(); KieContainerResourceList result = getResultMessage( mockEndpoint.getExchanges().get( 0 ) ).getBody( KieContainerResourceList.class ); assertEquals("Number of listed containers", 2, result.getContainers().size()); }
@Test public void testInvalidSchematronTransmogrifier() throws InterruptedException, IOException { mockOutput.expectedMessageCount(1); producerTemplate.sendBody("direct:input23", content("/schematron/schematron-test-fail.xml")); mockOutput.assertIsSatisfied(); String result = (String)mockOutput.getExchanges().get(0).getIn().getBody(); assertTrue(result.contains("svrl:failed-assert")); }
@Test public void testValidator2() throws InterruptedException { error.expectedMessageCount(1); Exchange exchange = producerTemplate.send("direct:validator-test", ExchangePattern.InOut, exchange1 -> exchange1.getIn().setBody("incorrect")); assertEquals(ValidationException.class, exchange.getException().getClass()); error.assertIsSatisfied(2000); }
@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(); }
public void run() throws Exception { context = createCamelContext(); context.addRoutes(createRouteBuilder()); template = context.createProducerTemplate(); context.start(); testManageTracer(); template.stop(); context.stop(); }
private void sendData(CamelContext context, List<String> messages) { ProducerTemplate template = context.createProducerTemplate(); for (String message : messages) { Exchange exchange = context.getEndpoint(directEndpoint.toString()).createExchange(); Message msg = exchange.getIn(); msg.setBody(message); template.send(directEndpoint.toString(), exchange); } }
public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); // Set up the ActiveMQ JMS Components ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:51616"); // Note we can explicit name of the component context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); context.start(); ProducerTemplate template = context.createProducerTemplate(); String out = template.requestBodyAndHeader("jms:queue:loan", null, Constants.PROPERTY_SSN, "Client-A", String.class); System.out.println(out); template.stop(); context.stop(); }
private void resendWithDelay(Exchange message) { if (retryProducer == null) { retryProducer = camelContext.createProducerTemplate(); retryProducer.setDefaultEndpointUri(context.getEndpoints().getDelayedInputUri()); } message.getIn().setHeader(MESSAGE_RESENT_ID_HEADER, message.getExchangeId()); retryProducer.send(message); logger.debug("Successfully resent message for plugin '{}' with id '{}'", context.getId(), message.getExchangeId()); }
@Test public void testSessionInsertMessage() throws Exception { Person person = new Person(); person.setName( "Bob" ); template.sendBody( "direct:test-message", person ); ArgumentCaptor<ObjectInsertedEvent> oie = ArgumentCaptor.forClass( ObjectInsertedEvent.class ); verify( wmel ).objectInserted( oie.capture() ); assertThat( (Person) ((Message) oie.getValue().getObject()).getBody(), is( person ) ); }
public static Map<?, ?> getItem(CamelContext camelctx) { HashMap<String, AttributeValue> key = new HashMap<>(); key.put("Id", new AttributeValue().withN("103")); Exchange exchange = new ExchangeBuilder(camelctx) .withHeader(DdbConstants.OPERATION, DdbOperations.GetItem) .withHeader(DdbConstants.KEY, key).build(); ProducerTemplate producer = camelctx.createProducerTemplate(); producer.send("direct:start", exchange); Assert.assertNull(exchange.getException()); return exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class); }
camelContext.start(); template = camelContext.createProducerTemplate(); String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4"; String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||"; in.append(line2); template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString()); } finally { if (template != null) { try { template.stop(); } catch (Exception e) { camelContext.stop(); } catch (Exception e) {
Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames(); for (CamelContext camelContext : camelContexts.values()) { String camelContextID = camelContext.getName(); List<RouteDefinition> routeDefinitions = modelCamelContext.getRouteDefinitions(); if (camelContextsConfigured.add(camelContextID)) { NodeIdFactory nodeIdFactory = camelContext.getNodeIdFactory(); ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); try { for (RouteDefinition routeDefinition : routeDefinitions) { if (data != null) { producerTemplate.sendBody(endpoint, data); producerTemplate.stop();
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(); } }
protected void sendMessage(final String uri, final Object body, final Map<String, Object> properties) { Exchange exchange = new DefaultExchange(contextFactory.getCamelContext()); for (Map.Entry<String, Object> property : properties.entrySet()) { exchange.setProperty(property.getKey(), property.getValue()); LOG.debug("Added property {}", property.getKey()); } DefaultMessage message = new DefaultMessage(contextFactory.getCamelContext()); message.setBody(body); exchange.setIn(message); ProducerTemplate template = contextFactory.getCamelContext().createProducerTemplate(); template.send(uri, exchange); }
public void testManageTracer() throws Exception { System.out.println("Connect to JConsole and try managing Tracer by enabling and disabling it on individual routes"); MockEndpoint mock = context.getEndpoint("jms:queue:orders", MockEndpoint.class); mock.expectedMessageCount(100); for (int i = 0; i < 100; i++) { template.sendBody("file://target/rider/orders", "" + i + ",4444,20100110,222,1"); } mock.await(100 * 10, TimeUnit.SECONDS); System.out.println("Complete sending 100 files will stop now"); }