use of org.apache.camel.ProducerTemplate in project camel by apache.
the class DefaultProducerTemplateWithCustomCacheMaxSizeTest method testCacheProducers.
public void testCacheProducers() throws Exception {
ProducerTemplate template = context.createProducerTemplate();
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
// test that we cache at most 500 producers to avoid it eating to much memory
for (int i = 0; i < 203; i++) {
Endpoint e = context.getEndpoint("seda:queue:" + i);
template.sendBody(e, "Hello");
}
// the eviction is async so force cleanup
template.cleanUp();
assertEquals("Size should be 200", 200, template.getCurrentCacheSize());
template.stop();
// should be 0
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class StreamResequencerTest method testMultithreaded.
public void testMultithreaded() throws Exception {
int numMessages = 100;
Object[] bodies = new Object[numMessages];
for (int i = 0; i < numMessages; i++) {
bodies[i] = "msg" + i;
}
getMockEndpoint("mock:result").expectedBodiesReceived(bodies);
getMockEndpoint("mock:result").setResultWaitTime(20000);
ProducerTemplate producerTemplate = context.createProducerTemplate();
ProducerTemplate producerTemplate2 = context.createProducerTemplate();
ExecutorService service = context.getExecutorServiceManager().newFixedThreadPool(this, getName(), 2);
service.execute(new Sender(producerTemplate, 0, numMessages, 2));
service.execute(new Sender(producerTemplate2, 1, numMessages, 2));
assertMockEndpointsSatisfied();
ServiceHelper.stopServices(producerTemplate, producerTemplate2);
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class BindyCsvFieldEndingWithSeparatorIssueTest method testBindyMoreSeparators.
@Test
public void testBindyMoreSeparators() throws Exception {
CamelContext ctx = new DefaultCamelContext();
ctx.addRoutes(createRoute());
ctx.start();
String addressLine1 = "8506 SIX FORKS ROAD, , ,,, ,";
MockEndpoint mock = ctx.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedPropertyReceived("addressLine1", addressLine1);
String csvLine = "\"PROBLEM SOLVER\",\"" + addressLine1 + "\",\"SUITE 104\",\"RALEIGH\",\"NC\",\"27615\",\"US\"";
ProducerTemplate template = ctx.createProducerTemplate();
template.sendBody("direct:fromCsv", csvLine.trim());
mock.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class HBaseConvertionsTest method testPutMultiRows.
@Test
public void testPutMultiRows() throws Exception {
if (systemReady) {
ProducerTemplate template = context.createProducerTemplate();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(), key[0]);
headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(), INFO_FAMILY);
headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(), column[0]);
headers.put(HBaseAttribute.HBASE_VALUE.asHeader(), body[0]);
headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(2), key[1]);
headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(2), INFO_FAMILY);
headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(2), column[0]);
headers.put(HBaseAttribute.HBASE_VALUE.asHeader(2), body[1]);
headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(3), key[2]);
headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(3), INFO_FAMILY);
headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(3), column[0]);
headers.put(HBaseAttribute.HBASE_VALUE.asHeader(3), body[2]);
headers.put(HBaseConstants.OPERATION, HBaseConstants.PUT);
template.sendBodyAndHeaders("direct:start", null, headers);
Configuration configuration = hbaseUtil.getHBaseAdmin().getConfiguration();
Connection conn = ConnectionFactory.createConnection(configuration);
Table bar = conn.getTable(TableName.valueOf(PERSON_TABLE));
Get get = new Get(Bytes.toBytes((Integer) key[0]));
//Check row 1
get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
Result result = bar.get(get);
byte[] resultValue = result.value();
assertArrayEquals(Bytes.toBytes((Long) body[0]), resultValue);
//Check row 2
get = new Get(Bytes.toBytes((String) key[1]));
get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
result = bar.get(get);
resultValue = result.value();
assertArrayEquals(Bytes.toBytes((Boolean) body[1]), resultValue);
//Check row 3
get = new Get(Bytes.toBytes((String) key[2]));
get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
result = bar.get(get);
resultValue = result.value();
assertArrayEquals(Bytes.toBytes((String) body[2]), resultValue);
IOHelper.close(bar);
}
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class TempReplyToIssueTest method handleMessage.
public String handleMessage(@Header("JMSReplyTo") final Destination jmsReplyTo, @Header("JMSCorrelationID") final String id, @Body String body, Exchange exchange) throws Exception {
assertNotNull(jmsReplyTo);
assertTrue("Should be a temp queue", jmsReplyTo.toString().startsWith("temp-queue"));
// we send the reply manually (notice we just use a bogus endpoint uri)
ProducerTemplate producer = exchange.getContext().createProducerTemplate();
producer.send("activemq:queue:xxx", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello Moon");
// remember to set correlation id
exchange.getIn().setHeader("JMSCorrelationID", id);
// this is the real destination we send the reply to
exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, jmsReplyTo);
}
});
// stop it after use
producer.stop();
// sleep a bit so Camel will send the reply a bit later
Thread.sleep(1000);
// and exceptions will be logged etc
return "Hello " + body;
}
Aggregations