ProducerTemplate tmp = ctx.createProducerTemplate(); tmp.setDefaultEndpoint(ctx.getEndpoint(uri+"&partitioner={{partitioner.class}}")); ctx.start(); tmp.sendBodyAndHeader("my test is working "+(new Random()).nextInt(100), KafkaConstants.PARTITION_KEY, 1); tmp.stop(); ctx.stop();
/** * Sends message for next asynchronous processing. * * @param msg the message */ protected void sendForNextProcessing(Message msg) { try { getProducerTemplate().sendBodyAndHeader(AsynchConstants.URI_ASYNC_MSG, ExchangePattern.InOnly, msg, AsynchConstants.MSG_QUEUE_INSERT_HEADER, System.currentTimeMillis()); } catch (CamelExecutionException ex) { LOG.error("Error occurred in message " + msg.toHumanString() + " processing", ex); throw ex; } }
/** * Performs ftp transfer of generated kela-opti files. * @throws Exception */ public void transferFiles() throws Exception { LOG.info("transferFiles: "); String targetUrl = String.format("%s%s%s%s%s%s%s%s%s%s", protocol, "://", username, "@", host, targetPath, "?password=", password, "&ftpClient.dataTimeout=", dataTimeout + "&passiveMode=true"); LOG.info("Target url: " + targetUrl); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiliWriter.fileName), Exchange.FILE_NAME, this.optiliWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiniWriter.fileName), Exchange.FILE_NAME, this.optiniWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiolWriter.fileName), Exchange.FILE_NAME, this.optiolWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optituWriter.fileName), Exchange.FILE_NAME, this.optituWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiopWriter.fileName), Exchange.FILE_NAME, this.optiopWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiyhWriter.fileName), Exchange.FILE_NAME, this.optiyhWriter.getFileLocalName()); producerTemplate.sendBodyAndHeader(targetUrl, new File(optiytWriter.fileName), Exchange.FILE_NAME, this.optiytWriter.getFileLocalName()); LOG.info("Files transfered"); }
@Override public boolean run(String line) { if (!line.contains("latexmlc")) return false; HashMap<String, String> props = parse(line); String latexmlCmd = CommUtils.SerializeToQuery(props); getContext().createProducerTemplate().sendBodyAndHeader("direct:compileLaTeXML", latexmlCmd, "JMSCorrelationID", props.get("source")); return false; } };
producerTemplate.sendBodyAndHeader(targetURI, ExchangePattern.InOnly, msg, AsynchConstants.MSG_QUEUE_INSERT_HEADER, System.currentTimeMillis());
@Test public void testCustomParamsClosure() throws InterruptedException { mockOutput.expectedBodiesReceived("dcba"); producerTemplate.sendBodyAndHeader("direct:input6", "blah", "foo", "abcd"); mockOutput.assertIsSatisfied(); }
@Test public void testValidatorProfileExpression() throws InterruptedException { mockOutput.expectedBodiesReceived("blah"); producerTemplate.sendBodyAndHeader("direct:input8", "blah", "profile", "derived"); mockOutput.assertIsSatisfied(); }
@Test public void testPredicate2() throws InterruptedException { mock.expectedMessageCount(0); producerTemplate.sendBodyAndHeader("direct:predicate-test-2", "body", "foo", "wrong"); mock.assertIsSatisfied(); // no need to wait (route is synchronous) }
@Test public void testCustomInputOrdering() throws InterruptedException { mockOutput.expectedBodiesReceived("kniooink"); producerTemplate.sendBodyAndHeader("direct:input10", "blah", "foo", "oink"); mockOutput.assertIsSatisfied(); }
@Test public void testClosureTwoParams() throws InterruptedException { mockOutput.expectedBodiesReceived("blah-blub"); producerTemplate.sendBodyAndHeader("direct:input2", "blah", "foo", "blub"); mockOutput.assertIsSatisfied(); }
@Test public void testCustomInputExpression() throws InterruptedException { mockOutput.expectedBodiesReceived("knio"); producerTemplate.sendBodyAndHeader("direct:input3", "blah", "foo", "oink"); mockOutput.assertIsSatisfied(); }
@Test public void testCustomInputClosure() throws InterruptedException { mockOutput.expectedBodiesReceived("knioknio"); producerTemplate.sendBodyAndHeader("direct:input4", "blah", "foo", "oink"); mockOutput.assertIsSatisfied(); }
@Test public void testCustomParamsExpression() throws InterruptedException { mockOutput.expectedBodiesReceived("dcba"); producerTemplate.sendBodyAndHeader("direct:input5", "blah", "foo", "abcd"); mockOutput.assertIsSatisfied(); }
@Test public void testXmlClosureHeadersAndBuilderParams() throws InterruptedException { mockOutput.expectedBodiesReceived("<result>magic</result>"); producerTemplate .sendBodyAndHeader("direct:input12", "ma", "foo", "gic"); mockOutput.assertIsSatisfied(); }
@Test public void testExtension() throws Exception { result.expectedMessageCount(1); result.expectedBodiesReceived("the_body-the_header-hello"); template.sendBodyAndHeader("the_body", "ExtensionHeader", "the_header"); result.assertIsSatisfied(); }
@Test public void testExtension() throws Exception { result.expectedMessageCount(1); result.expectedBodiesReceived("the_body-the_header-hello"); template.sendBodyAndHeader("the_body", "ExtensionHeader", "the_header"); result.assertIsSatisfied(); }
@Test public void testSendXMLWhichShouldPassThroughUnchanged() throws Exception { String xmlContentType = "text/xml"; String expectedBody = "<foo>bar</foo>"; resultEndpoint.expectedBodiesReceived(expectedBody); resultEndpoint.allMessages().header(Exchange.CONTENT_TYPE).isEqualTo(xmlContentType); template.sendBodyAndHeader(expectedBody, Exchange.CONTENT_TYPE, xmlContentType); resultEndpoint.assertIsSatisfied(); }
camelProducer.sendBodyAndHeader("hazelcastmq:queue:dummy", "Hello World!", "CamelHzMqDestination", "queue:primo.test"); camelProducer.sendBodyAndHeader("hazelcastmq:queue:dummy", "Goodbye World!", "CamelHzMqDestination", "queue:secondo.test");