當前位置: 首頁>>代碼示例>>Java>>正文


Java ProducerTemplate.sendBody方法代碼示例

本文整理匯總了Java中org.apache.camel.ProducerTemplate.sendBody方法的典型用法代碼示例。如果您正苦於以下問題:Java ProducerTemplate.sendBody方法的具體用法?Java ProducerTemplate.sendBody怎麽用?Java ProducerTemplate.sendBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.camel.ProducerTemplate的用法示例。


在下文中一共展示了ProducerTemplate.sendBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMocksAreValid

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String)body);
    assertEquals("Bob", outJson.get("FirstName").asText());
    assertEquals("Vila", outJson.get("LastName").asText());
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
 
開發者ID:atlasmap,項目名稱:camel-atlasmap,代碼行數:19,代碼來源:AtlasMapComponentTest.java

示例2: testMocksAreValid

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode sfJson = mapper.readTree((String)body);
    assertNotNull(sfJson.get("TwitterScreenName__c"));
    assertEquals("bobvila1982", sfJson.get("TwitterScreenName__c").asText());
}
 
開發者ID:atlasmap,項目名稱:camel-atlasmap,代碼行數:17,代碼來源:AtlasMapComponentJavaToJsonTest.java

示例3: testSeparateNotSucceed

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testSeparateNotSucceed() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    Status s = Util.generateMockTwitterStatus();
    when(s.getUser().getName()).thenReturn("BobVila");
    producerTemplate.sendBody("direct:start", s);

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String)body);
    assertEquals("BobVila", outJson.get("FirstName").asText());
    assertNull(outJson.get("LastName"));
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
 
開發者ID:atlasmap,項目名稱:camel-atlasmap,代碼行數:21,代碼來源:AtlasMapComponentTest.java

示例4: testCamelProducer

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
public void testCamelProducer() throws Exception {
    // Starting Spring context.
    try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
        context.start();

        // Sending Camel message.
        CamelContext camel = context.getBean(CamelContext.class);
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        // Waiting for the engine to process an event.
        Engine engine = context.getBean(Engine.class);
        await().atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());

        assertFalse(engine.isError());
        context.stop();
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:21,代碼來源:SimpleCamelProducerTest.java

示例5: testAutoStartupTrue

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
public void testAutoStartupTrue() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupTrueTest.xml");

    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();

    assertEquals(true, camel.getRouteStatus("bar").isStarted());

    // and now we can send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);

    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();

    mock.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:RouteAutoStartupPropertiesTest.java

示例6: main

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
public static void main(final String[] args) throws Exception {
    System.out.println("Notice this client requires that the CamelServer is already running!");

    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

    // get the camel template for Spring template style sending of messages (= producer)
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

    System.out.println("Invoking the multiply with 22");
    // 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);
    System.out.println("... the result is: " + response);

    // we're done so let's properly close the application context
    IOHelper.close(context);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:CamelClient.java

示例7: testCamelContext

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
public void testCamelContext() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);

    assertEquals("MyCamel", context.getName());

    ProducerTemplate template = context.createProducerTemplate();

    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);

    template.sendBody("seda:foo", "Hello World");

    mock.assertIsSatisfied();
    template.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:SingleRouteTest.java

示例8: testBindySeparatorsAround

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
@Ignore("This issue will be revisit when we have chance to rewrite bindy parser")
public void testBindySeparatorsAround() throws Exception {
    CamelContext ctx = new DefaultCamelContext();
    ctx.addRoutes(createRoute()); // new ReconciliationRoute()
    ctx.start();

    // TODO The separator in the beginning of the quoted field is still not handled.
    // We may need to convert the separators in the quote into some kind of safe code 
    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();

}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:BindyCsvFieldEndingWithSeparatorIssueTest.java

示例9: testMain

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
public void testMain() throws Exception {
    main.start();
    List<CamelContext> contexts = main.getCamelContexts();
    assertEquals("Expected size : " + contexts, 1, contexts.size());
    CamelContext camelContext = contexts.get(0);

    ProducerTemplate template = main.getCamelTemplate();
    assertNotNull("should have a template!", template);
    MockEndpoint endpoint = camelContext.getEndpoint(uri, MockEndpoint.class);
    endpoint.expectedBodiesReceived(expectedBody);

    template.sendBody(uri, expectedBody);

    endpoint.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:MainTest.java

示例10: testCamel1RecipientList

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
public void testCamel1RecipientList() throws Exception {
    String body = "<hello>world!</hello>";

    // seda:foo has no consumer in camel-1 so we should not expect any messages to be routed to result/foo
    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(0);

    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("seda:foo", body);
    template.stop();

    Thread.sleep(200);
    
    result.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:PojoDualCamelContextConsumerTest.java

示例11: testStandalone

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
public void testStandalone() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    });
    context.start();

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

    ProducerTemplate template = context.createProducerTemplate();
    template.sendBody("direct:start", "Hello World");

    mock.assertIsSatisfied();

    template.stop();
    context.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:CamelContextStandaloneTest.java

示例12: testMocksAreValid

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);

    final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", new ByteArrayInputStream("{\"field1\":\"value1\"}".getBytes()));

    MockEndpoint.assertIsSatisfied(camelContext);
    final Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(Pojo.class, body.getClass());
    assertEquals("value1", ((Pojo) body).getField1());
}
 
開發者ID:atlasmap,項目名稱:camel-atlasmap,代碼行數:14,代碼來源:AtlasMapComponentJsonToJavaTest.java

示例13: add

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Override
public Task add(TaskOptions task) {
  long etaMillis = task.getEtaMillis() - System.currentTimeMillis();
  if (etaMillis > 0) {
    DelayScheduler.getInstance().schedule(task, Constants.DEFAULT);
  } else {
    // get the camel template for Spring template style sending of messages (= producer)
    ProducerTemplate
        camelTemplate =
        AppFactory.get().getTaskService().getContext()
            .getBean("camel-client", ProducerTemplate.class);
    camelTemplate.sendBody("direct:tasks", ExchangePattern.InOnly, task);
  }
  return new SimpleTask(task);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:16,代碼來源:JMSTaskQueue.java

示例14: generate

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
public static void generate(Long domainId, int eventId, Map<String, Object> params, String objectType, String objectId,
                     CustomOptions customOptions, Object eventObject) throws EventGenerationException {
  EventData eventData = new EventData(domainId,eventId,params, objectType, objectId,
      customOptions, eventObject);
  try {
    ProducerTemplate
        camelTemplate =
        getContext()
            .getBean("camel-events-gen", ProducerTemplate.class);
    camelTemplate.sendBody("direct:events", ExchangePattern.InOnly, eventData);
  }catch (Exception e){
    throw new EventGenerationException(e);
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:15,代碼來源:EventPublisher.java

示例15: testCamelProducerOverridenAction

import org.apache.camel.ProducerTemplate; //導入方法依賴的package包/類
@Test
public void testCamelProducerOverridenAction() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer_overridden_action.py").build();
    registry.put("spongeEngine", engine);
    CamelContext camel = new DefaultCamelContext(registry);

    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() {
            // @formatter:off
            from("direct:start").routeId("spongeProducer")
                .to("sponge:spongeEngine");
            // @formatter:on
        }
    });

    camel.start();

    try {
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        await().pollDelay(2, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_camelEvent").get());

        assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_spongeProducer").get());
        assertFalse(engine.isError());
    } finally {
        camel.stop();
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:34,代碼來源:CamelProducerOverriddenActionTest.java


注:本文中的org.apache.camel.ProducerTemplate.sendBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。