Java 类org.apache.camel.component.amqp.AMQPComponent 实例源码

项目:Camel    文件:AMQPComponentAutoConfiguration.java   
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(AMQPComponent.class)
public AMQPComponent configureAMQPComponent(CamelContext camelContext,
        AMQPComponentConfiguration configuration) throws Exception {
    AMQPComponent component = new AMQPComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    IntrospectionSupport.setProperties(camelContext,
            camelContext.getTypeConverter(), component, parameters);
    return component;
}
项目:gytheio    文件:BenchmarkRunner.java   
/**
 * Initializes a Camel context and configures routes and object marshaling with the given 
 * brokerUrl, enpoint, and messageConsumer.
 * 
 * @param brokerUrl
 * @param endpoint
 * @param messageConsumer
 * @return the Gytheio message producer
 * @throws Exception
 */
protected MessageProducer initializeCamelEndpoint(
        final String brokerUrl, final String endpointSend, final String endpointReceive,
        final MessageConsumer messageConsumer) throws Exception
{
    CamelContext context = new DefaultCamelContext();

    ConnectionFactory connectionFactory = 
            new ActiveMQConnectionFactory(brokerUrl);
    JmsComponent component = AMQPComponent.jmsComponent();
    component.setConnectionFactory(connectionFactory);
    context.addComponent("amqp", component);

    final DataFormat dataFormat = new JacksonDataFormat(
            ObjectMapperFactory.createInstance(), Object.class);

    if (messageConsumer != null)
    {
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("amqp:" + endpointReceive).unmarshal(dataFormat).bean(messageConsumer, "onReceive");
            }
        });
    }

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:benchmark.test").marshal(dataFormat).to("amqp:" + endpointSend);
        }
    });

    CamelMessageProducer messageProducer = new CamelMessageProducer();
    messageProducer.setProducer(context.createProducerTemplate());
    messageProducer.setEndpoint("direct:benchmark.test");

    context.start();

    return messageProducer;
}