当前位置: 首页>>代码示例>>Java>>正文


Java ProducerTemplate类代码示例

本文整理汇总了Java中org.apache.camel.ProducerTemplate的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate类的具体用法?Java ProducerTemplate怎么用?Java ProducerTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProducerTemplate类属于org.apache.camel包,在下文中一共展示了ProducerTemplate类的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: testWithDirectEndpoint

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Test
public void testWithDirectEndpoint(TestContext context) throws Exception {
  Async async = context.async();
  Endpoint endpoint = camel.getEndpoint("direct:foo");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(fromCamel("direct:foo").toVertx("test")));

  vertx.eventBus().consumer("test", message -> {
    context.assertEquals("hello", message.body());
    async.complete();
  });

  camel.start();
  BridgeHelper.startBlocking(bridge);

  ProducerTemplate producer = camel.createProducerTemplate();
  producer.asyncSendBody(endpoint, "hello");
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:20,代码来源:InboundEndpointTest.java

示例3: 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

示例4: 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

示例5: getProducerTemplate

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
public ProducerTemplate getProducerTemplate() {
    ProducerTemplate result = producerTemplate;

    // https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
    if (result == null) {
        synchronized (this) {
            result = producerTemplate;
            if (result == null) {
                result = camelContext.getRegistry().lookupByNameAndType(PRODUCER_TEMPLATE, ProducerTemplate.class);
            }

            if (result == null) {
                // Create a new ProducerTemplate when there is none in the Camel registry.
                result = camelContext.createProducerTemplate();
                producerTemplateCreatedManually = true;
            }

            producerTemplate = result;
        }
    }

    return result;
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:24,代码来源:CamelPlugin.java

示例6: 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

示例7: xxxTestForkAndJoin

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
public void xxxTestForkAndJoin() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(NUMBER_OF_MESSAGES);

    ProducerTemplate template = context.createProducerTemplate();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        template.sendBodyAndHeader("seda:fork", "Test Message: " + i,
                "seqnum", new Long(i));
    }

    long expectedTime = NUMBER_OF_MESSAGES
            * (RandomSleepProcessor.MAX_PROCESS_TIME + RandomSleepProcessor.MIN_PROCESS_TIME)
            / 2 / CONCURRENCY + TIMEOUT;
    Thread.sleep(expectedTime);

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:RouteContextProcessorTest.java

示例8: testMarshalViaDozer

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Test
public void testMarshalViaDozer() throws Exception {

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").convertBodyTo(HashMap.class);
        }
    });

    DozerBeanMapperConfiguration mconfig = new DozerBeanMapperConfiguration();
    mconfig.setMappingFiles(Arrays.asList("bean-to-map-dozer-mappings.xml"));
    new DozerTypeConverterLoader(context, mconfig);

    context.start();
    try {
        ProducerTemplate producer = context.createProducerTemplate();
        Map<?, ?> result = producer.requestBody("direct:start", new Customer("John", "Doe", null), Map.class);
        Assert.assertEquals("John", result.get("firstName"));
        Assert.assertEquals("Doe", result.get("lastName"));
    } finally {
        context.stop();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:DozerBeanMappingTest.java

示例9: testReplyWithCustomType

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Test
public void testReplyWithCustomType() throws Exception {
  Endpoint endpoint = camel.getEndpoint("direct:stuff");

  vertx.eventBus().registerDefaultCodec(Person.class, new PersonCodec());

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addInboundMapping(new InboundMapping().setAddress("test-reply").setEndpoint(endpoint)));

  vertx.eventBus().consumer("test-reply", message -> {
    message.reply(new Person().setName("alice"));
  });

  camel.start();
  BridgeHelper.startBlocking(bridge);

  ProducerTemplate template = camel.createProducerTemplate();
  Future<Object> future = template.asyncRequestBody(endpoint, new Person().setName("bob"));
  Person response = template.extractFutureBody(future, Person.class);
  assertThat(response.getName()).isEqualTo("alice");
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:22,代码来源:InboundReplyTest.java

示例10: testRequestUsingDefaultEndpoint

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
public void testRequestUsingDefaultEndpoint() throws Exception {
    ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:out"));
    producer.start();

    Object out = producer.requestBody("Hello");
    assertEquals("Bye Bye World", out);

    out = producer.requestBodyAndHeader("Hello", "foo", 123);
    assertEquals("Bye Bye World", out);

    Map<String, Object> headers = new HashMap<String, Object>();
    out = producer.requestBodyAndHeaders("Hello", headers);
    assertEquals("Bye Bye World", out);

    out = producer.requestBodyAndHeaders("Hello", null);
    assertEquals("Bye Bye World", out);

    producer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:DefaultProducerTemplateTest.java

示例11: doPost

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    /**
     * Get message and name parameters sent on the POST request
     */
    String message = request.getParameter("message");
    String name = request.getParameter("name");

    /**
     * Create a ProducerTemplate to invoke the direct:start endpoint, which will
     * result in the greeting web service 'greet' method being invoked.
     *
     * The web service parameters are sent to camel as an object array which is
     * set as the request message body.
     *
     * The web service result string is returned back for display on the UI.
     */
    ProducerTemplate producer = camelContext.createProducerTemplate();
    Object[] serviceParams = new Object[] { message, name };
    String result = producer.requestBody("direct:start", serviceParams, String.class);

    request.setAttribute("greeting", result);
    request.getRequestDispatcher("/greeting.jsp").forward(request, response);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:25,代码来源:CamelCxfWsServlet.java

示例12: testCacheProducersFromContext

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
public void testCacheProducersFromContext() throws Exception {
    ProducerTemplate template = context.createProducerTemplate(500);

    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 < 503; 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 500", 500, template.getCurrentCacheSize());
    template.stop();

    // should be 0
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:DefaultProducerTemplateTest.java

示例13: testJettyMulticastJmsFile

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Test
public void testJettyMulticastJmsFile() throws Exception {
    TestSupport.deleteDirectory("target/jetty");

    ProducerTemplate template = camelContext.createProducerTemplate();

    String out = template.requestBody(URL, "Hello World", String.class);
    assertEquals("Bye World", out);

    template.stop();

    ConsumerTemplate consumer = camelContext.createConsumerTemplate();
    String in = consumer.receiveBody("jms:queue:foo", 5000, String.class);
    assertEquals("Hello World", in);

    String in2 = consumer.receiveBody("file://target/jetty?noop=true&readLock=none", 5000, String.class);
    assertEquals("Hello World", in2);

    consumer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JettyMulticastJmsFileTest.java

示例14: doPost

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
  Map<String, Object> headers = new HashMap<>();

  Enumeration<String> parameterNames = request.getParameterNames();
  while(parameterNames.hasMoreElements()) {
    String parameterName = parameterNames.nextElement();
    String parameterValue = request.getParameter(parameterName);
    headers.put(parameterName, parameterValue);
  }

  try {
    ProducerTemplate producer = camelContext.createProducerTemplate();
    producer.sendBodyAndHeaders("direct:sendmail", request.getParameter("message"), headers);
    request.getRequestDispatcher("/success.jsp").forward(request, response);
  } catch (CamelExecutionException e) {
    request.setAttribute("error", e);
    request.getRequestDispatcher("/error.jsp").forward(request, response);
  }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:21,代码来源:MailSendServlet.java

示例15: doPost

import org.apache.camel.ProducerTemplate; //导入依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    /**
     * Get message and name parameters sent on the POST request
     */
    String message = request.getParameter("message");
    String name = request.getParameter("name");

    /**
     * Create a ProducerTemplate to invoke the direct:start endpoint, which will
     * result in the greeting web service 'greet' method being invoked.
     *
     * The web service parameters are sent to camel as an object array which is
     * set as the request message body.
     *
     * The web service result string is returned back for display on the UI.
     */
    ProducerTemplate producer = camelContext.createProducerTemplate();
    Object[] serviceParams = new Object[] {message, name};
    String result = producer.requestBody("direct:start", serviceParams, String.class);

    request.setAttribute("greeting", result);
    request.getServletContext().getRequestDispatcher("/greeting.jsp").forward(request, response);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:25,代码来源:CamelCxfWsServlet.java


注:本文中的org.apache.camel.ProducerTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。