You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by zpyoung <zp...@gmail.com> on 2015/12/04 05:12:36 UTC

Re: Camel and Activemq setup with Spring Boot

Any help on this?



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-and-Activemq-setup-with-Spring-Boot-tp5774544p5774651.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel and Activemq setup with Spring Boot

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

Spring Boot creates connectionFactory bean for you. It is named
"jmsConnectionfactory" [1]. In order to wire Camel with Spring Boot AMQ
support, you have to refer that bean from JMS component URI:

  from("jms:queue?connectionFactory=#jmsConnectionfactory").to(...);

Simple as that :)

Cheers!

[1]
https://github.com/spring-projects/spring-boot/blob/90f7bc03216c709634ea7ffd3832482e25e0ace3/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java#L45

sob., 5.12.2015 o 15:01 użytkownik zpyoung <zp...@gmail.com> napisał:

> Really just trying to make sure I understand how the configuration works.
> If
> I auto configure activemq with Spring Boot, I have noticed that an activemq
> component is also created in the camel context.  Is Spring Boot creating
> this component or the camel context?
>
> So when I need to have a component configured differently, should I make
> the
> configuration changes on the endpoint or just create a different component?
>
> Are there really any differences between these two configurations?
>
> -----------------------------------
> create new component to handle transaction.
>    @Bean
>     public ActiveMQComponent activemqtx(PooledConnectionFactory
> pooledConnectionFactory) {
>         ActiveMQComponent activeMQComponent = new ActiveMQComponent();
>         activeMQComponent.setTransacted(true);
>         activeMQComponent.setTransactionManager(new
> JmsTransactionManager(pooledConnectionFactory));
>         return activeMQComponent;
>     }
>
>    from("activemq:TRIGGER").routeId("Trigger")
>                 .onException(Exception.class)
>                     .maximumRedeliveries(2)
>                     .to("activemq:EXCEPTION")
>                     .markRollbackOnlyLast().end()
>                 .transacted()
>                 .bean("jpaRepository")
>                 .to("log:out");
>
> Or just configure the enpoint.
>
>    from("activemq:TRIGGER?transacted=true").routeId("Trigger")
>                 .onException(Exception.class)
>                     .maximumRedeliveries(7)
>                     .to("activemq:EXCEPTION")
>                     .markRollbackOnlyLast().end()
>                 .transacted()
>                 .bean("jpaRepository")
>                 .to("log:out");
>
>
> I'm guessing that creating a component allows for better reuse if you have
> several routes using the same configuration.
>
> Sample code I have been testing with
> https://github.com/zachariahyoung/docker-camel
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-and-Activemq-setup-with-Spring-Boot-tp5774544p5774728.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
-- 
Henryk Konsek
http://about.me/hekonsek

Re: Camel and Activemq setup with Spring Boot

Posted by zpyoung <zp...@gmail.com>.
Really just trying to make sure I understand how the configuration works.  If
I auto configure activemq with Spring Boot, I have noticed that an activemq
component is also created in the camel context.  Is Spring Boot creating
this component or the camel context?

So when I need to have a component configured differently, should I make the
configuration changes on the endpoint or just create a different component?

Are there really any differences between these two configurations?

-----------------------------------
create new component to handle transaction.
   @Bean
    public ActiveMQComponent activemqtx(PooledConnectionFactory
pooledConnectionFactory) {
        ActiveMQComponent activeMQComponent = new ActiveMQComponent();
        activeMQComponent.setTransacted(true);
        activeMQComponent.setTransactionManager(new
JmsTransactionManager(pooledConnectionFactory));
        return activeMQComponent;
    }

   from("activemq:TRIGGER").routeId("Trigger")
                .onException(Exception.class)
                    .maximumRedeliveries(2)
                    .to("activemq:EXCEPTION")
                    .markRollbackOnlyLast().end()
                .transacted()
                .bean("jpaRepository")
                .to("log:out");

Or just configure the enpoint.

   from("activemq:TRIGGER?transacted=true").routeId("Trigger")
                .onException(Exception.class)
                    .maximumRedeliveries(7)
                    .to("activemq:EXCEPTION")
                    .markRollbackOnlyLast().end()
                .transacted()
                .bean("jpaRepository")
                .to("log:out");


I'm guessing that creating a component allows for better reuse if you have
several routes using the same configuration.

Sample code I have been testing with
https://github.com/zachariahyoung/docker-camel




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-and-Activemq-setup-with-Spring-Boot-tp5774544p5774728.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel and Activemq setup with Spring Boot

Posted by Joakim Bjørnstad <jo...@gmail.com>.
Hello,

I'd check out the source of JmsAutoConfiguration and
ActiveMQAutoConfiguration to see what Spring Boot autoconfigures.
Essentially everything under the
org.springframework.boot.autoconfigure package.

For example ActiveMQ can be configured by supplying ActiveMQProperties
through Spring Boot externalized configuration.
spring.activemq.brokerUrl
spring.activemq.inMemory
spring.activemq.pooled
spring.activemq.user
spring.activemq.password

So you can probably cut a bean or two if you go that way. Also IMO not
necessary to explicitly add components to the camel context. Register
a Component bean in Spring and you can refer to it by methodname in
the camel URI. It gets automatically registered.

e.g.:

@Bean
@Inject
public JmsComponent myjms(ConnectionFactory myConnectionFactory) {
  JmsComponent jmsComponent = new JmsComponent();
  jmsComponent.setConnectionFactory(myConnectionFactory);
  return jmsComponent;
}

The component should automatically be available in Camel (same should
go for ActiveMQComponent): myjms:MY_QUEUE?concurrentConsumers=10

But what is the issue really, just clean up Spring config or is there
something not working with your config ?


On Fri, Dec 4, 2015 at 5:12 AM, zpyoung <zp...@gmail.com> wrote:
> Any help on this?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-and-Activemq-setup-with-Spring-Boot-tp5774544p5774651.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad