当前位置: 首页>>代码示例>>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;未经允许,请勿转载。