Search in sources :

Example 1 with JmsComponent

use of org.apache.camel.component.jms.JmsComponent in project camel by apache.

the class JmsReconnectTest method testRequestReply.

/**
     * This test is disabled as the problem can currently not be reproduced using ActiveMQ.
     * TODO Find a way to recreate the problem with ActiveMQ and fully automate the test
     * @throws Exception
     */
@Ignore
@Test
public void testRequestReply() throws Exception {
    BrokerService broker = new BrokerService();
    broker.addConnector("tcp://localhost:61616");
    broker.setPersistent(false);
    broker.setTimeBeforePurgeTempDestinations(1000);
    broker.start();
    DefaultCamelContext context = new DefaultCamelContext();
    JmsComponent jmsComponent = new JmsComponent();
    /**
         * 
         */
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("failover://(tcp://localhost:61616)?maxReconnectAttempts=1");
    /**
         * When using Tibco EMS the problem can be recreated. As the broker is
         * external it has to be stopped and started by hand.
         */
    // TibjmsConnectionFactory connectionFactory = new TibjmsConnectionFactory();
    // connectionFactory.setReconnAttemptCount(1);
    jmsComponent.setConnectionFactory(connectionFactory);
    jmsComponent.setRequestTimeout(1000);
    jmsComponent.setReceiveTimeout(1000);
    context.addComponent("jms", jmsComponent);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jms:testqueue").bean(new EchoServiceImpl());
            from("direct:test").to("jms:testqueue");
        }
    });
    CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
    processor.setCamelContext(context);
    processor.postProcessBeforeInitialization(this, "this");
    context.start();
    String ret = proxy.echo("test");
    Assert.assertEquals("test", ret);
    broker.stop();
    /**
         * Wait long enough for the jms client to do a full reconnect. In the
         * Tibco EMS case this means that a Temporary Destination created before
         * is invalid now
         */
    Thread.sleep(5000);
    System.in.read();
    broker.start(true);
    /**
         * Before the fix to this issue this call will throw a spring UncategorizedJmsException
         * which contains an InvalidJmsDestination
         */
    String ret2 = proxy.echo("test");
    Assert.assertEquals("test", ret2);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) JmsComponent(org.apache.camel.component.jms.JmsComponent) CamelBeanPostProcessor(org.apache.camel.spring.CamelBeanPostProcessor) BrokerService(org.apache.activemq.broker.BrokerService) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with JmsComponent

use of org.apache.camel.component.jms.JmsComponent in project camel by apache.

the class JmsPassThroughtJmsKeyFormatStrategyTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
    // configure to use passthrough
    JmsComponent activemq = jmsComponentAutoAcknowledge(connectionFactory);
    activemq.setJmsKeyFormatStrategy("passthrough");
    camelContext.addComponent("activemq", activemq);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ConnectionFactory(javax.jms.ConnectionFactory) JmsComponent(org.apache.camel.component.jms.JmsComponent)

Example 3 with JmsComponent

use of org.apache.camel.component.jms.JmsComponent in project camel by apache.

the class JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    // no redeliveries
    ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(null, 0);
    JmsComponent component = jmsComponentTransacted(connectionFactory);
    camelContext.addComponent("activemq", component);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ConnectionFactory(javax.jms.ConnectionFactory) JmsComponent(org.apache.camel.component.jms.JmsComponent)

Example 4 with JmsComponent

use of org.apache.camel.component.jms.JmsComponent in project camel by apache.

the class JmsTransactedOnExceptionRollbackOnExceptionTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    // no redeliveries
    ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(null, 0);
    JmsComponent component = jmsComponentTransacted(connectionFactory);
    camelContext.addComponent("activemq", component);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ConnectionFactory(javax.jms.ConnectionFactory) JmsComponent(org.apache.camel.component.jms.JmsComponent)

Example 5 with JmsComponent

use of org.apache.camel.component.jms.JmsComponent in project camel by apache.

the class JmsComponentAutoConfiguration method configureJmsComponent.

@Lazy
@Bean(name = "jms-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JmsComponent.class)
public JmsComponent configureJmsComponent(CamelContext camelContext, JmsComponentConfiguration configuration) throws Exception {
    JmsComponent component = new JmsComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : JmsComponent(org.apache.camel.component.jms.JmsComponent) HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

JmsComponent (org.apache.camel.component.jms.JmsComponent)25 ConnectionFactory (javax.jms.ConnectionFactory)21 JndiContext (org.apache.camel.util.jndi.JndiContext)16 CamelContext (org.apache.camel.CamelContext)6 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActiveMQSslConnectionFactory (org.apache.activemq.ActiveMQSslConnectionFactory)1 BrokerService (org.apache.activemq.broker.BrokerService)1 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)1 JmsConfiguration (org.apache.camel.component.jms.JmsConfiguration)1 PassThroughJmsKeyFormatStrategy (org.apache.camel.component.jms.PassThroughJmsKeyFormatStrategy)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 CamelBeanPostProcessor (org.apache.camel.spring.CamelBeanPostProcessor)1 JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1