Search in sources :

Example 16 with ProducerTemplate

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());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint)

Example 17 with ProducerTemplate

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);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ExecutorService(java.util.concurrent.ExecutorService)

Example 18 with ProducerTemplate

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 19 with ProducerTemplate

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);
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Connection(org.apache.hadoop.hbase.client.Connection) Result(org.apache.hadoop.hbase.client.Result) Get(org.apache.hadoop.hbase.client.Get) Test(org.junit.Test)

Example 20 with ProducerTemplate

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;
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3