Spring Boot + ActiveMQ example

In this tutorial, we will see how to create Spring boot + ActiveMQ example.
Spring boot comes with embedded ActiveMQ similar to tomcat, so you don’t have to create external ActiveMQ.If want to configure with external ActiveMQ, you can do it just by change in application.properties file.

Github Source code:

Project Structure:

Spring Boot ActiveMQ example

Here are steps to create Spring Boot + ActiveMQ example.
Step 1:  Create a simple java  project using maven in eclipse named "SpringBootActiveMQExample".
Step 2: Change "pom.xml" as below:

The spring-boot-starter-parent provides you all maven defaults required for any spring project.
Since we are developing a spring application integrated with activemq, we also need to add spring-boot-starter-activemq dependency.
This will include additional dependencies such Spring boot, activemq etc which are required for this application.
Step 3: Create a file named "MessageCreator.java" in package .org.arpit.java2blog.springboot

Step 4: Create a file named "MessageReceiver.java" in package .org.arpit.java2blog.springboot

@JMSListner:This Annotation is actually used to mark a method to be the target of a JMS message listener on the specified destination().

Step 5: Create a file named “application.properties” in package /src/main/resources

If you want to use external activemq, just use below application.properties

Please note that you just need to provide ActiveMQ broker url, if you specify above property then Spring boot won’t create another in memory embedded ActiveMQ.

Step 6: Create a file named "SpringBootApplicatioMain.java" in package .org.arpit.java2blog

We have just added @SpringBootApplication and it does all the work.
Let’s understand more about this annotation.
@SpringBootApplication is an annotation that adds all of the following:

@Configuration makes the class as a source of bean definitions for the application context.
@EnableAutoConfiguration enables Spring boot to add beans presents in classpath setting and various property setting.
This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
@ComponentScan tells Spring to look for other components, configurations, and services in the default package, allowing it to find the controllers.
If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.
@EnableJMS annotation is used to trigger search for method annotated with @JMSListener, hence to create JMS listener in the background.

When you run above program, you will get below output:

2017-04-30 19:14:44.271 INFO 8757 — [ main] o.a.activemq.broker.TransportConnector : Connector vm://localhost started
Message has been put to queue by sender
2017-04-30 19:14:44.438 INFO 8757 — [ main] o.a.java2blog.SpringBootApplicatioMain : Started SpringBootApplicatioMain in 2.852 seconds (JVM running for 3.548)
Message Received: Hello Java2blog!!

That ‘s all about Spring Boot + ActiveMQ example.Please comment you find any issue.


import_contacts

You may also like:

Related Posts

  • 11 January

    Spring boot JDBC example

    Table of ContentsTools usedProject StructureCreate new Spring boot projectMaven configurationConfigure datasource in Application.propertiesCreate database tableCreate model classCreate Repository interface and implementationCreate service interface and implementationCreate Application classRun the applicationVerify database outputGithub Source code In this post, we will see Spring boot JDBC example. As we already know Spring boot does lot of auto configurations which […]

  • 02 January

    Spring boot devtools tutorial

    Table of ContentsOverviewJRebelIntroduction to Spring Boot DevToolsAdding Devtools to your projectSpring Boot DevTools FeaturesProperty DefaultsLoggingCachingAutomatic RestartLive ReloadGlobal SettingsRemote ApplicationsFile System WatchersConclusion In this post, we’ll be looking up what does spring has to offer for developer experience. Overview Using IDEs like Eclipse, Spring Tool Suite, Intellij Idea a typical development setup includes an application code […]

  • 26 December

    Spring boot H2 Database example

    Table of ContentsWhat is H2 database?Tools usedGithub Source code:Project StructureCreate new Spring boot projectMaven configurationH2 database configurationOverride H2 databse defaultsModelRepositoryServiceControllerSpring boot main fileRun the applicationTest the applicationCreate movie objectGet all movie objectsDelete movie id 3 In this post, we are going to see how to create Spring boot application integrating with H2 database. What is […]

  • 22 December

    Spring Boot CrudRepository

    Table of ContentsTools usedProject Structure:Wiring up MongoDBThe Repository ClassThe Save methodThe User Entity ClassBringing the UserDao and CrudRepository togetherServiceControllerApplication classRunning the code sampleConclusionSource code In this post, we’ll be looking up how to create and use Spring Boot CrudRepository. SpringBoot CrudRepository provides sophisticated CRUD functionality for the type of entity you want to be managed.This […]

  • 10 April

    Difference between Spring and Spring boot

    Table of ContentsSpring frameworkSpring bootAdvantages of Spring BootSpring vs Spring boot In this post, we will see difference between Spring and Spring boot. If you have followed spring project over time, you might have noticed it has become increasingly complex. If you want to create a spring application, you still need to put a lot […]

  • 17 September

    Spring Boot SOAP Web service Example

    Table of ContentsTools usedProject structureAdd wsdl4j dependencyXSD file to define domainGenerate domain classes based on XSDCreate Book repository with dummy dataDefine Book service endpointDefine web service configurationRun the applicatonTest WSDL URLTest Spring soap web serviceSource code In this post, we will see how to create soap web services with Spring boot. We will create contract […]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.