Package org.apache.camel

Examples of org.apache.camel.ProducerTemplate


        mockA.expectedBodiesReceived("Hello A");

        MockEndpoint mockB = camelB.getEndpoint("mock:mock2", MockEndpoint.class);
        mockB.expectedBodiesReceived("Hello B");

        ProducerTemplate producer1 = camelA.createProducerTemplate();
        producer1.sendBody("direct:start1", "Hello A");

        ProducerTemplate producer2 = camelB.createProducerTemplate();
        producer2.sendBody("direct:start2", "Hello B");

        // make sure we properly stop the services we created
        ServiceHelper.stopServices(producer1, producer2);

        mockA.assertIsSatisfied();
View Full Code Here


    }
      
   
    private void runTests(CamelContext context) throws Exception {
        MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
        ProducerTemplate template = context.createProducerTemplate();
       
        String expectedBody = "<matched/>";

        resultEndpoint.expectedBodiesReceived(expectedBody);

        template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");

        resultEndpoint.assertIsSatisfied();
       
        resultEndpoint.reset();
       
        resultEndpoint.expectedMessageCount(0);

        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");

        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here

            context.start();

            MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
            mock.setExpectedMessageCount(1);

            ProducerTemplate template = context.createProducerTemplate();
            if (e != null) {
                template.send("direct:in", e);
            } else {
                template.sendBodyAndHeaders("direct:in", payload, headers);
            }
            assertMockEndpointsSatisfied();
            return mock.getReceivedExchanges().get(0);
        } finally {
            context.stop();
View Full Code Here

    @Test
    public void testMocksAreValid() throws Exception {
        TestSupport.deleteDirectory("target/greeter/response");
        assertNotNull(camelContext);
       
        ProducerTemplate template = camelContext.createProducerTemplate();
       
        Object result = template.sendBody("direct:start", ExchangePattern.InOut ,
                                                   REQUEST);
       
        assertEquals("The result is wrong.", "Hello Willem", result);
       
        File file = new File("target/greeter/response/response.txt");
View Full Code Here

public class RedeliveryErrorHandlerAsyncDelayedTwoCamelContextIssueTest {

    @Test
    public void shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped() throws Exception {
        DefaultCamelContext context1 = createContext();
        ProducerTemplate producer1 = context1.createProducerTemplate();
        ConsumerTemplate consumer1 = context1.createConsumerTemplate();
        context1.start();
        producer1.sendBody("seda://input", "Hey1");
        Exchange ex1 = consumer1.receive("seda://output", 5000);

        DefaultCamelContext context2 = createContext();
        ProducerTemplate producer2 = context2.createProducerTemplate();
        ConsumerTemplate consumer2 = context2.createConsumerTemplate();
        context2.start();

        // now stop 1, and see that 2 is still working
        context1.stop();

        producer2.sendBody("seda://input", "Hey2");
        Exchange ex2 = consumer2.receive("seda://output", 5000);

        Assert.assertNotNull(ex1);
        Assert.assertEquals("Hey1", ex1.getIn().getBody());
        Assert.assertNotNull(ex2);
View Full Code Here

   
    protected void camelClientInvocation() {
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

        // get the camel template for Spring template style sending of messages (= producer)
        ProducerTemplate camelTemplate = (ProducerTemplate) context.getBean("camelTemplate");
       
        // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
        int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
       
        assertEquals("Get a wrong response", 66, response);
       
        context.stop();
       
View Full Code Here

        context.stop();
    }

    @ManagedOperation(description = "Send body (in only)")
    public void sendBody(String endpointUri, String body) throws Exception {
        ProducerTemplate template = context.createProducerTemplate();
        try {
            template.sendBody(endpointUri, body);
        } finally {
            template.stop();
        }
    }
View Full Code Here

        }
    }

    @ManagedOperation(description = "Request body (in out)")
    public Object requestBody(String endpointUri, String body) throws Exception {
        ProducerTemplate template = context.createProducerTemplate();
        Object answer = null;
        try {
            answer = template.requestBody(endpointUri, body);
        } finally {
            template.stop();
        }
        return answer;
    }
View Full Code Here

        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean("camel");
        assertValidContext(context);

        // now lets send a message
        ProducerTemplate template = context.createProducerTemplate();
        template.start();
        template.send("direct:start", new Processor() {
            public void process(Exchange exchange) {
                Message in = exchange.getIn();
                in.setHeader("name", "James");
                in.setBody(body);
            }
        });
        template.stop();

        MyProcessor myProcessor = (MyProcessor) applicationContext.getBean("myProcessor");
        List<Exchange> list = myProcessor.getExchanges();
        assertEquals("Should have received a single exchange: " + list, 1, list.size());
    }
View Full Code Here

        // Note we can explicit name of the component
        context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

        context.addRoutes(new Client());

        ProducerTemplate template = context.createProducerTemplate();

        context.start();
        // START SNIPPET: sending
        // send out the request message
        for (int i = 0; i < 2; i++) {
            template.sendBodyAndHeader("test-jms:queue:loanRequestQueue",
                                       "Quote for the lowerst rate of loaning bank",
                                       Constants.PROPERTY_SSN, "Client" + i);
            Thread.sleep(100);
        }
        // END SNIPPET: sending
View Full Code Here

TOP

Related Classes of org.apache.camel.ProducerTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.