EnableJMS

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

EnableJMS

hlopez
Hello,

I have a program created with Spring Boot which should consume messages from a JMS Queue.
In spring boot I'm using config/AppConfig.java which looks like:
@EnableJms
@Configuration
@Import(OtherConfig.class)
public class AppConfig {

    @Autowired
    private ConnectionFactory connectionFactory;

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }
}

I would like the class that uses the config above to receive messages from JMS Destination, lets say my class is called MyListener which contains a method containing @JmsListener.

In my citrus context I want to use an embedded activeMQ so I use the following:
    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost:61616?broker.persistent=false"/>
    </bean>

How do I configure Citrus to start this MyListener? I'm creating a bean of it in the citrus-context but it is not consuming any messages.

Secondly how to see which beans has been created by citrus? I'm not seeing that in the logging.

Humphrey
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

Christoph Deppisch
Administrator
I recommend starting your whole Spring Boot application in prior to executing the Citrus tests instead of loading only the listener class as bean in Citrus. You can do this with spring-boot-maven-plugin in Maven pre-integration-test phase for instance.

Also I think you are missing the embedded ActiveMQ message broker. Just using the connection factory is not enough. You can use an embedded broker bean in the Citrus application context. You could also use the activemq-maven-plugin in pre-integration-test phase in Maven though.

I think you should have a look at the samples here:

http://citrusframework.org/samples/jms/
https://github.com/christophd/citrus-samples/tree/master/sample-jms

and

https://github.com/christophd/citrus-samples/tree/master/sample-bakery
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

hlopez
Thanks for pointing that out.
I know the following is maven related but how does this profile get activated during the citrus test?

  <profiles>
    <profile>
      <id>activemq-embedded</id>
      <activation>
        <property>
          <name>embedded</name>
        </property>
      </activation>

As shown in the https://github.com/christophd/citrus-samples/tree/master/sample-jms
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

Christoph Deppisch
Administrator
You can activate the profile via system property.

mvn integration-test -Dembedded=true
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

hlopez
Thanks I found out via google that you can run it with -Dembedded=true to activate the profile.
But what is the difference in running it with this parameter or running it in vm mode?
With the vm mode it works when I run directly from the IDE with normal testng way. So no need to startup a broker manually first or pass parameters in the run configuration.
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

Christoph Deppisch
Administrator
vm mode? What is that exactly?
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

hlopez
Take a look at the broker url provided before:

<property name="brokerURL" value="vm://localhost:61616?broker.persistent=false"/>

I'm using vm instead of tcp.
vm://localhost

http://activemq.apache.org/vm-transport-reference.html

Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

hlopez
Hi, maybe a bit out of topic and on the other hand maybe not.

Let say my application (SUT) is consuming messages on Q1 and putting messages on Q2. My application consist out of (one or more) spring boot application(s).
The normal way would be to have it always running before doing the test.
Is there a way to configure that in a way that in the pre-integration-test step of maven this will be started?
In some cases I need to start like 3 separate JVMs, and will they could be stopped in the post-integration-test step?
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

hlopez
I think I found something for this:

https://docs.spring.io/spring-boot/docs/current/maven-plugin/plugin-info.html

I could configure maven with spring-boot:start and spring-boot:stop goals.
Reply | Threaded
Open this post in threaded view
|

Re: EnableJMS

Christoph Deppisch
Administrator
The Citrus samples are using such a pre-integration-test setup with automatic jetty server deployments.

https://github.com/christophd/citrus-samples

Have a look at the POM files in that sample repository and you will see in profile jetty-embedded how it is done.

https://github.com/christophd/citrus-samples/blob/master/sample-http/pom.xml

Also see this advanced jetty configuration where multiple WAR files are deployed to the same jetty instance with different port mappings:

https://github.com/christophd/citrus-samples/blob/master/sample-bakery/integration/pom.xml
https://github.com/christophd/citrus-samples/blob/master/sample-bakery/integration/src/jetty/jetty-embedded.xml

Spring Boot maven plugin is totally valid option, too.