What's New Here?

jetbrains-intellijidea-logo

Coloring Different Data Sources in IntelliJ IDEA

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));The database plugin in IntelliJ IDEA is a useful tool to work with data in databases. As long as we got a JDBC driver to connect to the database we can configure a data source. And then we can run queries, inspect the contents of tables and change data with the database tool window. It is not uncommon to have multiple data sources, for example development and test environment databases, which will have the same tables. When we open the tables or run queries we don’t have a visual feedback to see to which data source such a table belongs. To have a visual feedback we can colorize our data source. This means we assign a color to a data source and when we open a table from that data source the tab color in the editor window will have a different color than other tabs or the background color of the data source objects have a color. To add a color to a data source we must open the database tool window and right click on a data source. We select the option Color Settings… from the popup window:Next a new dialog opens where we can select a color:We can make a selection for one of the predefined colors or create a custom color we want to use. Also we can select in the Appearance Settings where in IntelliJ IDEA the colored data source must appear. We click on the OK button to save our settings. We can repeat these steps for other data sources and given them different colors. Once we have added color to our data source we can see for example in the tabs of our editor window the different colors:Or when we open the data sources in the database tool window to get a list of all objects in the data source:Even we open a dialog to see recently changed files we can see the colorized data source objects:Sample with IntelliJ IDEA 13.1.1Reference: Coloring Different Data Sources in IntelliJ IDEA from our JCG partner Hubert Ikkink at the JDriven blog....
apache-maven-logo

Maven and Java multi-version modules

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));Introduction Usually, a project has a minimum Java version requirement and that applies to all of its modules. But every rule has its exceptions, as recently I stumbled on the following issue. One open source project of mine mandates Java 1.6 for most of its modules, except one requiring the 1.7 version. This happens when integrating external libraries having different Java requirements than your own project. Because that one module integrates the DBCP2 framework (supporting at least Java 1.7), I need to instruct Maven to use two different Java compilers. Environment variables We need to define the following environment variablesEnvironment Variable Name Environment Variable ValueJAVA_HOME_6 C:\Program Files\Java\jdk1.6.0_38JAVA_HOME_7 C:\Program Files\Java\jdk1.7.0_25JAVA_HOME %JAVA_HOME_6%The parent pom.xml The parent pom.xml defines the global java version settings <properties> <jdk.version>6</jdk.version> <jdk>${env.JAVA_HOME_6}</jdk> </properties> We need to instruct both the compiler and the test plugins to use the configured java version. <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <executable>${jdk}/bin/javac</executable> <fork>true</fork> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <jvm>${jdk}/bin/java</jvm> <forkMode>once</forkMode> </configuration> </plugin> </plugins> </build> The specific module pom.xml Those modules requiring a different java version, just need to override the default settings: <properties> <jdk.version>7</jdk.version> <jdk>${env.JAVA_HOME_7}</jdk> </properties> And that’s it, we can now build each modules using its own specific minimum java version requirement.Reference: Maven and Java multi-version modules from our JCG partner Vlad Mihalcea at the Vlad Mihalcea’s Blog blog....
java-logo

New BigInteger Methods in Java 8

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));Attention to new features in JDK 8 has rightfully been largely focused on new language features and syntax. However, there are some nice additions to the libraries and APIs and in this post I cover four new methods added to the BigInteger class: longValueExact(), intValueExact(), shortValueExact(), and byteValueExact(). All four of the newly introduced “xxxxxExact()” methods throw an ArithmeticException if the number contained in the BigInteger instance cannot be provided in the specified form (specified in the method’s name) without loss of information. BigInteger already had methods intValue() and longValue() as well as inherited (from Number) methods shortValue() and byteValue(). These methods do not throw exceptions if the BigInteger value loses information in the presentation as one of these types. Although at first glance this may seem like an advantage, it means that code that uses the results of these methods uses values that are not accurate without any ability to know that information was lost. The new “xxxxxExact” methods throw an ArithmenticException rather than pretending to provide a result that has lost significant information. The following simple code listing demonstrates the “legacy” methods that present wrong data in types byte, short, int, and long rather than throwing an exception. The same code also demonstrates use of the new “xxxxxExact” methods that throw an exception when information is lost rather than presenting a bad representation. The output of running this code follows the code and demonstrates how the methods behave differently when the BigInteger contains a value with more information than the returned byte, short, int, or long can represent. BigIntegerDem.java package dustin.examples.jdk8;import static java.lang.System.out; import java.math.BigInteger;/** * Demonstrate the four new methods of BigInteger introduced with JDK 8. * * @author Dustin */ public class BigIntegerDemo { /** * Demonstrate BigInteger.byteValueExact(). */ private static void demonstrateBigIntegerByteValueExact() { final BigInteger byteMax = new BigInteger(String.valueOf(Byte.MAX_VALUE)); out.println("Byte Max: " + byteMax.byteValue()); out.println("Byte Max: " + byteMax.byteValueExact()); final BigInteger bytePlus = byteMax.add(BigInteger.ONE); out.println("Byte Max + 1: " + bytePlus.byteValue()); out.println("Byte Max + 1: " + bytePlus.byteValueExact()); }/** * Demonstrate BigInteger.shortValueExact(). */ private static void demonstrateBigIntegerShortValueExact() { final BigInteger shortMax = new BigInteger(String.valueOf(Short.MAX_VALUE)); out.println("Short Max: " + shortMax.shortValue()); out.println("Short Max: " + shortMax.shortValueExact()); final BigInteger shortPlus = shortMax.add(BigInteger.ONE); out.println("Short Max + 1: " + shortPlus.shortValue()); out.println("Short Max + 1: " + shortPlus.shortValueExact()); }/** * Demonstrate BigInteger.intValueExact(). */ private static void demonstrateBigIntegerIntValueExact() { final BigInteger intMax = new BigInteger(String.valueOf(Integer.MAX_VALUE)); out.println("Int Max: " + intMax.intValue()); out.println("Int Max: " + intMax.intValueExact()); final BigInteger intPlus = intMax.add(BigInteger.ONE); out.println("Int Max + 1: " + intPlus.intValue()); out.println("Int Max + 1: " + intPlus.intValueExact()); }/** * Demonstrate BigInteger.longValueExact(). */ private static void demonstrateBigIntegerLongValueExact() { final BigInteger longMax = new BigInteger(String.valueOf(Long.MAX_VALUE)); out.println("Long Max: " + longMax.longValue()); out.println("Long Max: " + longMax.longValueExact()); final BigInteger longPlus = longMax.add(BigInteger.ONE); out.println("Long Max + 1: " + longPlus.longValue()); out.println("Long Max + 1: " + longPlus.longValueExact()); }/** * Demonstrate BigInteger's four new methods added with JDK 8. * * @param arguments Command line arguments. */ public static void main(final String[] arguments) { System.setErr(out); // exception stack traces to go to standard output try { demonstrateBigIntegerByteValueExact(); } catch (Exception exception) { exception.printStackTrace(); }try { demonstrateBigIntegerShortValueExact(); } catch (Exception exception) { exception.printStackTrace(); }try { demonstrateBigIntegerIntValueExact(); } catch (Exception exception) { exception.printStackTrace(); }try { demonstrateBigIntegerLongValueExact(); } catch (Exception exception) { exception.printStackTrace(); } } } The Output Byte Max: 127 Byte Max: 127 Byte Max + 1: -128 java.lang.ArithmeticException: BigInteger out of byte range at java.math.BigInteger.byteValueExact(BigInteger.java:4428) at dustin.examples.jdk8.BigIntegerDemo.demonstrateBigIntegerByteValueExact(BigIntegerDemo.java:23) at dustin.examples.jdk8.BigIntegerDemo.main(BigIntegerDemo.java:75) Short Max: 32767 Short Max: 32767 Short Max + 1: -32768 java.lang.ArithmeticException: BigInteger out of short range at java.math.BigInteger.shortValueExact(BigInteger.java:4407) at dustin.examples.jdk8.BigIntegerDemo.demonstrateBigIntegerShortValueExact(BigIntegerDemo.java:36) at dustin.examples.jdk8.BigIntegerDemo.main(BigIntegerDemo.java:84) Int Max: 2147483647 Int Max: 2147483647 Int Max + 1: -2147483648 java.lang.ArithmeticException: BigInteger out of int range at java.math.BigInteger.intValueExact(BigInteger.java:4386) at dustin.examples.jdk8.BigIntegerDemo.demonstrateBigIntegerIntValueExact(BigIntegerDemo.java:49) at dustin.examples.jdk8.BigIntegerDemo.main(BigIntegerDemo.java:93) Long Max: 9223372036854775807 Long Max: 9223372036854775807 Long Max + 1: -9223372036854775808 java.lang.ArithmeticException: BigInteger out of long range at java.math.BigInteger.longValueExact(BigInteger.java:4367) at dustin.examples.jdk8.BigIntegerDemo.demonstrateBigIntegerLongValueExact(BigIntegerDemo.java:62) at dustin.examples.jdk8.BigIntegerDemo.main(BigIntegerDemo.java:102) As the above output demonstrates, the new BigInteger methods with “xxxxxExact” in their name will not present inaccurate representations when the returned type cannot hold the information in BigInteger instance. Although exceptions are generally not one of our favorite things, they are almost always going to be better than getting and using wrong data and not even realizing it is wrong.Reference: New BigInteger Methods in Java 8 from our JCG partner Dustin Marx at the Inspired by Actual Events blog....
grails-logo

The Grails depedency injection inheritance pitfall

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));This blog post is about a small pitfall you should be aware of when combining dependency injection in Grails with inheritance. I think the problem is best explained with a piece of example code. So let’s look at the following two definitions of Grails controllers.             class FooController {   TestService testService  def foo() {     // do something with testService   } } class BarController extends FooController {   TestService testService  def bar() {     // do something with testService   } } Both controllers look nearly identical. The only difference is that BarController extends FooController. Now assume we have an instance of BarController and we want to call the methods bar() and foo() on it. Guess what happens? The call of bar() works fine while the call of foo() throws a NullPointerException because testService is null. testService is a standard Groovy property. This means that the testService fields will become private and getter / setter methods are generated for both controllers. The getter / setter of BarController override the getter / setter of FooController. So whenever the dependency is injected using setTestService() only BarController retrieves the TestService instance. This is nothing special about Grails controllers, it works the same for services and other Groovy classes. The solution is easy: Remove the testService dependency from BarController. Whenever testService is accessed in BarController, it will use the appropriate getter of FooController and everything works. In this simple example the problem is quite obvious and can be easily solved. However, if your classes become larger this can be a bit tricky to debug. Assume you have a base class with multiple sub classes. Whenever you want to add a new dependency to your base class, you have to check all the subclasses. If one of the sub classes already defines the same dependency you have to remove it or it will not be available in your base class.Reference: The Grails depedency injection inheritance pitfall from our JCG partner Michael Scharhag at the mscharhag, Programming and Stuff blog....
github-logo

How to add an IntelliJ project to GitHub

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));Although the GitHub docs contains good info on how to add an existing GitHub project to your local machine, how to add an existing (unversioned) project from your local machine to GitHub was a little less clear to me. Here are the steps I use. From IntelliJSelect ‘VCS’ menu -> Import in Version Control -> Share project on GitHub. You may be prompted for you GitHub, or IntelliJ Master, password Select the files to commitIn the latest version (v13) of IntelliJ, you will then be prompted for which files you wish to include as part of the initial commit. Obviously deselect anything in the target (aka classes) folder. I also exclude the .idea folder. Click OK and you new project and files should now be available via GitHub! In older versions of IntelliJ, this step (somewhat strangely) created the project with just the readme. Follow the the next step to add the other files. To add more files:Select files to add Right click -> Git -> Add Commit files (Ctrl-K or VCS -> Git -> Commit) [Commit & push easier, but can also just Commit] If files not pushed in step above, VCS -> Git -> PushFrom command line I think the following steps do the same thing from the command line, but it has been a while since I used them:Create a new repository cd to your project directory e.g. cd projects/newproject Run the following git commandsgit init git add . 
git commit -m “Initial commit” git remote add origin https://github.com/username/projectname.gitNotes:I think: git remote add origin git@github.com:username/projectname.git does the same thing. The ‘origin’ name is arbitrary (As with branch naming, remote alias names are arbitrary – just as ‘master’ has no special meaning but is widely used because git init sets it up by default, ‘origin’ is often used as a remote name because git clone sets it up by default as the cloned-from URL. You can really name it just about anything.)git push -u origin master (Note to remove a remote again: git remote rm origin)Resources http://stackoverflow.com/questions/2866872/how-to-upload-fresh-code-at-githubReference: How to add an IntelliJ project to GitHub from our JCG partner Shaun Abram at the Shaun Abram’s blog blog....
apache-hadoop-logo

Apache Hadoop 2.4.0

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));The Apache community has voted to release Apache Hadoop 2.4.0, so the new release is now available and consists of important improvements. The improvements are related not only to HDFS but also to MapReduce. The important improvement in HDFS is about NameNodes. Multiple independent Namenodes and Namespaces are now used that do not require coordination with each other. Datanodes are used as common storage for blocks by all Namenodes and each datanode registers with all Namenodes in the cluster. Heartbeats and block reports are sent from datanodes to Namenodes, that send back commands handled by the datanodes. MapReduce changes are mostly about the ResourceManager. Since 0.23 version of Hadoop the two major functions of the JobTracker, resource management and job life-cycle management were seperated into separate components. In this release, the new ResourceManager manages the global assignment of resources to applications and the per-application ApplicationMaster manages the application‚ scheduling and coordination. The per-application ApplicationMaster is a framework specific library and is tasked with negotiating resources from the ResourceManager and working with the NodeManager(s) to execute and monitor the tasks. Interested to get started with Hadoop? Check out our complimentary whitepaper “Hadoop Illuminated”! ...
apache-camel-logo

Circuit Breaker Pattern in Apache Camel

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));Camel is very often used in distributed environments for accessing remote resources. Remote services may fail for various reasons and periods. For services that are temporarily unavailable and recoverable after short period of time, a retry strategy may help. But some services can fail or hang for longer period of time making the calling application unresponsive and slow. A good strategy to prevent from cascading failures and exhaustion of critical resources is the Circuit Breaker pattern described by Michael Nygard in the Release It! book. Circuit Breaker is a stateful pattern that wraps the failure-prone resource and monitors for errors. Initially the Circuit Breaker is in closed state and passes all calls to the wrapped resource. When the failures reaches a certain threshold, the circuit moves to open state where it returns error to the caller without actually calling the wrapped resource. This prevents from overloading the already failing resource. While at this state, we need a mechanism to detect whether the failures are over and start calling the protected resource. This is where the third state called half-open comes into play. This state is reached after a certain time following the last failure. At this state, the calls are passed through to the protected resource, but the result of the call is important. If the call is successful, it is assumed that the protected resource has recovered and the circuit is moved into closed state, and if the call fails, the timeout is reset, and the circuit is moved back to open state where all calls are rejected. Here is the state diagram of Circuit Breaker from Martin Fowler’s post:How Circuit Breaker is implemented in Camel? Circuit Breaker is available in the latest snapshot version of Camel as a Load balancer policy. Camel Load Balancer already has policies for Round Robin, Random, Failover, etc. and now also CircuiBreaker policy. Here is an example load balancer that uses Circuit Breaker policy with threshold of 2 errors and halfOpenAfter timeout of 1 second. Notice also that this policy applies only to errors caused by MyCustomException new RouteBuilder() { public void configure() { from("direct:start").loadBalance() .circuitBreaker(2, 1000L, MyCustomException.class) .to("mock:result"); } }; And here is the same example using Spring XML DSL: <route> <from uri="direct:start"/> <loadBalance> <circuitBreaker threshold="2" halfOpenAfter="1000"> <exception>MyCustomException</exception> </circuitBreaker> <to uri="mock:result"/> </loadBalance> </route>Reference: Circuit Breaker Pattern in Apache Camel from our JCG partner Bilgin Ibryam at the OFBIZian blog....
java-logo

10 Books Every Java Developer Should Read

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));I have read my share of software development books and I have noticed that it is very rare to find a book which I want to read more than once. However, once in a while I find a book which teaches me new things every time when I read it. This blog post is a tribute to these rare gems. And now, without further delay, I present to you ten books which have earned a special place in my bookshelf:      Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin teaches you three things: how to write good code, how to tell the difference between good code and bad code, and how to transform bad code into good code. These are essential skills for every developer. That is why you should read this book. Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides is a true classic. It presents elegant solutions to common design problems. If you want to learn the basics of writing elegant object-oriented code, this is the book you should read. Domain Driven Design: Tacking the Complexity in the Heart of Software by Eric Evans is a book for developers who want to understand how they can transform the knowledge of domain experts into a useful domain model. If you have noticed that often it is hard to find a natural place for “business logic”, you should do yourself a favour and read this book. Effective Java by Joshua Bloch is a book that requires no introduction. If you want to write more robust Java code, you have 78 reasons to read this book. Effective Unit Testing: A guide for Java developers by Lasse Koskela is the second testing book of Lasse Koskela, and it helps you to improve the quality of your test suite. Reading this book helped me to write cleaner and more maintainable tests. I guess you could say that this book helped me to realize that tests have no value if they don’t express the intention of each test. I think that this is a valuable lesson, and that is why you should read this book too. Patterns of Enterprise Application Architecture by Martin Fowler has a “boring” title but you shouldn’t let it scare you. Reading this book gave me a better understanding about the basic building blocks of the “enterprise” frameworks which I use every day. If you want to understand your tools, this is the book you should read. Refactoring: Improving the Design of Existing Code by Martin Fowler is another timeless classic. It describes more than 40 different refactorings which can be used to improve the design of existing code. Every software developer should have good refactoring skills and reading this book will take you one step closer to that goal. SQL Antipatterns: Avoiding the Pitfalls of Database Programming by Bill Karwin is a book that is very useful to all developers who use relational databases. This book helps you to avoid the most common design antipatterns, query antipatterns, and application development antipatters. To be honest, I have to admit that I have made a few mistakes described in this book. That is why I am extremely happy that I read it and learned how I can avoid making the same mistakes in the future. SQL Performance Explained by Markus Winand promises that it will teach you everything you need to know about SQL performance. That is a very bold tagline and I was very happy when I realized that this book keeps its promise. I think that you should read this book for two reasons: it proves that relational databases aren’t slow, and it explains how you can make your SQL queries as fast as possible (they can faster than you ever imagined). Test Driven: TDD and Acceptance TDD for Java Developers by Lasse Koskela is the first testing book which I have ever read, and that is why it has a special place in my heart. It is a very good introduction to TDD, but you can learn a few testing tricks from this book even if you aren’t a TDD fanboy. That is why this book is a very good addition to your bookshelf.This list is based on my (subjective) opinion and it is very likely that your list will look completely different. If you think that I missed a book which should be in this list, share your opinion in the comment section.Reference: 10 Books Every Java Developer Should Read from our JCG partner Petri Kainulainen at the Petri Kainulainen blog....
apache-activemq-logo

Using ActiveMQ – “Master/Slave” configuration with failover protocol

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));Introduction ActiveMQ broker(s) tends to be a core piece of messaging infrastructure in an enterprise. It is vital for this messaging infrastructure to be highly available and scalable. Please read this link in order to learn more about creating network of brokers to support various use cases. One of the popular use case for ActiveMQ is the Master/Slave configuration with shared database. When this configuration is used, the message consumers and producers can operate without interruptions as they use ActiveMQ’s connection factory with failover protocol. The failover protocol insulates the consumers and producers from having to deal with any potential downtime or application level reconnection logic when slave ActiveMQ node takes over to become the master which happens if the current master node goes down for any reason. I must caution that this configuration must not be used to mask any issues which take out the master node. We should iron out any causes that result in an unplanned master node outage. Overview In this blog, I will demonstrate the following:Run 2 ActiveMQ nodes in a Master/Slave configuration with a shared KahaDB file based database. Configure ActiveMQ web console hosted in a Tomcat instance to point to whichever node is Master node in the cluster. Failover scenarios. Message publisher and consumer behavior oblivious to the failover.PrerequisitesInstall ActiveMQ version 5.8.0 Download ActiveMQ version 5.8.0 web console war from here Install Tomcat version 7.0.35 – To host the ActiveMQ Web Console applicationDeep Dive We will create a 2 node ActiveMQ cluster on the same Windows 7 machine. We will need to configure the ports (TCP & JMX) such that there is no conflict. ActiveMQ provides a script called “activemq-admin.bat” which helps in running multiple instances of ActiveMQ using the same binaries, very much like Tomcat. Let’s go ahead and create broker-1 and broker-2 instances. command: activemq-admin create <DIR-for-ActiveMQ-node> C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-1Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre   Heap sizes: current=125632k  free=124976k  max=1864192k     JVM args: -Dactivemq.classpath=C:\apache-activemq-5.8.0\bin\..\conf;C:\apache-activemq-5.8.0\bin\..\data; -Dactivemq.home=C:\apache-activemq-5.8.0 \bin\.. -Dactivemq.base=C:\apache-activemq-5.8.0\bin\.. -Dactivemq.data=C:\apache-activemq-5.8.0\bin\..\data -Djava.io.tmpdir=C:\apache-activemq-5.8.0 \bin\..\data\tmp -Dactivemq.conf=C:\apache-activemq-5.8.0\bin\..\conf Extensions classpath:   [C:\apache-activemq-5.8.0\bin\..\lib,C:\apache-activemq-5.8.0\bin\..\lib\camel,C:\apache-activemq-5.8.0\bin\..\lib\optional,C:\apache-activemq-5.8.0 \bin\..\lib\web,C:\apache-activemq-5.8.0\bin\..\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\data Running create broker task... Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1 Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1\bin Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1\conf Creating new file: C:\apache-activemq-5.8.0\cluster\broker-1\bin\broker-1.bat Creating new file: C:\apache-activemq-5.8.0\cluster\broker-1\bin\broker-1 Copying from: C:\apache-activemq-5.8.0\conf\activemq.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-command.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker1.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-dynamic-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker2.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-dynamic-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-jdbc.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-jdbc.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-scalability.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-security.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-specjms.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker1.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-static-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker2.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-static-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-stomp.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-stomp.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-throughput.xml Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.cert           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker-localhost.cert Copying from: C:\apache-activemq-5.8.0\conf\broker.ks           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ks Copying from: C:\apache-activemq-5.8.0\conf\broker.ts           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ts Copying from: C:\apache-activemq-5.8.0\conf\camel.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\camel.xml Copying from: C:\apache-activemq-5.8.0\conf\client.ks           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ks Copying from: C:\apache-activemq-5.8.0\conf\client.ts           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ts Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.properties           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials-enc.properties Copying from: C:\apache-activemq-5.8.0\conf\credentials.properties           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.properties           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-realm.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty.xml           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty.xml Copying from: C:\apache-activemq-5.8.0\conf\jmx.access           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.access Copying from: C:\apache-activemq-5.8.0\conf\jmx.password           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.password Copying from: C:\apache-activemq-5.8.0\conf\log4j.properties           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\log4j.properties Copying from: C:\apache-activemq-5.8.0\conf\logging.properties           to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\logging.properties Now let’s create broker-2 instance… C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-2Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre   Heap sizes: current=125632k  free=124976k  max=1864192k     JVM args: -Dactivemq.classpath=C:\apache-activemq-5.8.0\bin\..\conf;C:\apache-activemq-5.8.0\bin\..\data; -Dactivemq.home=C:\apache-activemq-5.8.0 \bin\.. -Dactivemq.base=C:\apache-activemq-5.8.0\bin\.. -Dactivemq.data=C:\apache-activemq-5.8.0\bin\..\data -Djava.io.tmpdir=C:\apache-activemq-5.8.0 \bin\..\data\tmp -Dactivemq.conf=C:\apache-activemq-5.8.0\bin\..\conf Extensions classpath:   [C:\apache-activemq-5.8.0\bin\..\lib,C:\apache-activemq-5.8.0\bin\..\lib\camel,C:\apache-activemq-5.8.0\bin\..\lib\optional,C:\apache-activemq-5.8.0 \bin\..\lib\web,C:\apache-activemq-5.8.0\bin\..\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\data Running create broker task... Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2 Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2\bin Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2\conf Creating new file: C:\apache-activemq-5.8.0\cluster\broker-2\bin\broker-2.bat Creating new file: C:\apache-activemq-5.8.0\cluster\broker-2\bin\broker-2 Copying from: C:\apache-activemq-5.8.0\conf\activemq.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-command.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker1.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-dynamic-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker2.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-dynamic-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-jdbc.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-jdbc.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-scalability.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-security.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-specjms.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker1.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-static-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker2.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-static-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-stomp.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-stomp.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-throughput.xml Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.cert           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker-localhost.cert Copying from: C:\apache-activemq-5.8.0\conf\broker.ks           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ks Copying from: C:\apache-activemq-5.8.0\conf\broker.ts           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ts Copying from: C:\apache-activemq-5.8.0\conf\camel.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\camel.xml Copying from: C:\apache-activemq-5.8.0\conf\client.ks           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ks Copying from: C:\apache-activemq-5.8.0\conf\client.ts           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ts Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.properties           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials-enc.properties Copying from: C:\apache-activemq-5.8.0\conf\credentials.properties           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.properties           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-realm.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty.xml           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty.xml Copying from: C:\apache-activemq-5.8.0\conf\jmx.access           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.access Copying from: C:\apache-activemq-5.8.0\conf\jmx.password           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.password Copying from: C:\apache-activemq-5.8.0\conf\log4j.properties           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\log4j.properties Copying from: C:\apache-activemq-5.8.0\conf\logging.properties           to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\logging.properties You may have noticed the following properties above: ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\dataThese properties need to be fixed as we’d like ACTIVEMQ_BASE and ACTIVEMQ_CONF to be different for both broker-1 and broker-2. We need to edit the following files:broker-1.bat in C:\apache-activemq-5.8.0\cluster\broker-1\bin directoryset ACTIVEMQ_HOME=”C:/apache-activemq-5.8.0″ set ACTIVEMQ_BASE=”C:/apache-activemq-5.8.0/cluster/broker-1″ set ACTIVEMQ_CONF=%ACTIVEMQ_BASE%/confbroker-2.bat in C:\apache-activemq-5.8.0\cluster\broker-2\bin directoryset ACTIVEMQ_HOME=”C:/apache-activemq-5.8.0″ set ACTIVEMQ_BASE=”C:/apache-activemq-5.8.0/cluster/broker-2″ set ACTIVEMQ_CONF=%ACTIVEMQ_BASE%/confYou may observe that both broker-1 and broker-2 nodes share the same ACTIVEMQ_DATA folder. Since we are using the in-built KahaDB for persistence, both broker-1 and broker-2 will share this. We need to differentiate the tcp ports for broker-1 and broker-2 and also enable JMX and configure  JMX ports for remote monitoring. Let’s edit the activemq.xml for broker-1 to fix tcp port: <transportConnectors> <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600"/> <!--<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireformat.maxFrameSize=104857600"/>--> </transportConnectors> Let’s edit the activemq.xml for broker-1 to enable JMX monitoring, notice useJMX=”true” attribute below. <broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker-1" dataDirectory="${activemq.data}" useJmx="true"> Let’s configure the JMX port <managementContext> <managementContext createConnector="true" connectorPort="1099"/> </managementContext> Repeat the same for broker-2. set TCP port to 61626 and JMX port to 2099. Start broker-1.  C:\apache-activemq-5.8.0\cluster\broker-1\bin>broker-1.bat Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre Heap sizes: current=1004928k free=994439k max=1004928k JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=C:/apache-activemq- 5.8.0/cluster/broker-1/conf;C:/apache-activemq-5.8.0/cluster/broker-1/conf;C:/apache-activemq-5.8.0/conf; -Dactivemq.home=C:/apache-activemq-5.8.0 -Da ctivemq.base=C:/apache-activemq-5.8.0/cluster/broker-1 -Dactivemq.conf=C:/apache-activemq-5.8.0/cluster/broker-1/conf -Dactivemq.data=C:/apache-active mq-5.8.0\data -Djava.io.tmpdir=C:/apache-activemq-5.8.0\data\tmp Extensions classpath: [C:\apache-activemq-5.8.0\cluster\broker-1\lib,C:\apache-activemq-5.8.0\lib,C:\apache-activemq-5.8.0\cluster\broker-1\lib\camel,C:\apache-activemq-5 .8.0\cluster\broker-1\lib\optional,C:\apache-activemq-5.8.0\cluster\broker-1\lib\web,C:\apache-activemq-5.8.0\cluster\broker-1\lib\extra,C:\apache-act ivemq-5.8.0\lib\camel,C:\apache-activemq-5.8.0\lib\optional,C:\apache-activemq-5.8.0\lib\web,C:\apache-activemq-5.8.0\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0 ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\cluster\broker-1 ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\cluster\broker-1\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\data Loading message broker from: xbean:activemq.xml INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@71060478: startup date [Tue Jul 09 16:59:15 CDT 2013]; root of context hierarchy INFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-1\tmp_storage] started INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\apache-activemq-5.8.0\data\kahadb] INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi INFO | KahaDB is version 4 INFO | Recovering from the journal ... INFO | Recovery replayed 1 operations from the journal in 0.028 seconds. INFO | Apache ActiveMQ 5.8.0 (broker-1, ID:AKUNTAMU-1-27777-1373407157813-0:1) is starting INFO | Listening for connections at: tcp://AKUNTAMU-1:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600 INFO | Connector openwire Started INFO | Apache ActiveMQ 5.8.0 (broker-1, ID:AKUNTAMU-1-27777-1373407157813-0:1) started INFO | For help or more information please see: http://activemq.apache.org WARN | Store limit is 102400 mb, whilst the data directory: C:\apache-activemq-5.8.0\data\kahadb only has 38889 mb of usable space ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\apache-activemq-5.8.0\data\broker-1\tmp_storage only has 38889 mb o f usable space INFO | Web console type: embedded INFO | ActiveMQ WebConsole initialized. INFO | Initializing Spring FrameworkServlet 'dispatcher' INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.xml, access to all MBeans is allowed Start broker-2. You will observe that broker-2 is unable to acquire the lock since broker-1 already grabbed it. broker-2 will keep retrying to acquire the lock every 10 seconds.  C:\apache-activemq-5.8.0\cluster\broker-2\bin>broker-2.bat Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre Heap sizes: current=1004928k free=994439k max=1004928k JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=C:/apache-activemq- 5.8.0/cluster/broker-2/conf;C:/apache-activemq-5.8.0/cluster/broker-2/conf;C:/apache-activemq-5.8.0/conf; -Dactivemq.home=C:/apache-activemq-5.8.0 -Da ctivemq.base=C:/apache-activemq-5.8.0/cluster/broker-2 -Dactivemq.conf=C:/apache-activemq-5.8.0/cluster/broker-2/conf -Dactivemq.data=C:/apache-active mq-5.8.0\data -Djava.io.tmpdir=C:/apache-activemq-5.8.0\data\tmp Extensions classpath: [C:\apache-activemq-5.8.0\cluster\broker-2\lib,C:\apache-activemq-5.8.0\lib,C:\apache-activemq-5.8.0\cluster\broker-2\lib\camel,C:\apache-activemq-5 .8.0\cluster\broker-2\lib\optional,C:\apache-activemq-5.8.0\cluster\broker-2\lib\web,C:\apache-activemq-5.8.0\cluster\broker-2\lib\extra,C:\apache-act ivemq-5.8.0\lib\camel,C:\apache-activemq-5.8.0\lib\optional,C:\apache-activemq-5.8.0\lib\web,C:\apache-activemq-5.8.0\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0 ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\cluster\broker-2 ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\cluster\broker-2\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\data Loading message broker from: xbean:activemq.xml INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@420f9c40: startup date [Tue Jul 09 17:02:55 CDT 2013]; root of context hierarchy INFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-2\tmp_storage] started INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\apache-activemq-5.8.0\data\kahadb] INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmi INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. Now let’s configure the ActiveMQ web console. By default, ActiveMQ distribution contains admin web console but in the Master/Slave configuration, it is unknown which node is the master. So it is doesn’t make sense to use the embedded web console. Hence it is best to have ActiveMQ web console outside of the ActiveMQ nodes. You can disable the embedded ActiveMQ Web Console in each node by commenting the following line in activemq.xml in conf directory of each ActiveMQ node. <!--<import resource="jetty.xml"/>--> For our example, we will deploy ActiveMQ Web Console web application in Tomcat container and then configure ActiveMQ web console application to intelligently point to the master node in ActiveMQ cluster. so let’s copy the activemq-web-console-5.8.0.war to webapps directory of Tomcat. Add the following line to catalina.bat set JAVA_OPTS=-Dwebconsole.type=properties -Dwebconsole.jms.url=failover:(tcp://localhost:61616,tcp://localhost:61626) -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi,service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmiNow let’s start Tomcat. C:\apache-tomcat-7.0.35\bin>.\catalina.bat run Using CATALINA_BASE: "C:\apache-tomcat-7.0.35" Using CATALINA_HOME: "C:\apache-tomcat-7.0.35" Using CATALINA_TMPDIR: "C:\apache-tomcat-7.0.35\temp" Using JRE_HOME: "C:\Program Files\Java\jdk1.6.0_31" Using CLASSPATH: "C:\apache-tomcat-7.0.35\bin\bootstrap.jar;C:\apache-tomcat-7.0.35\bin\tomcat-juli.jar" Jul 9, 2013 5:28:08 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8080"] Jul 9, 2013 5:28:08 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] Jul 9, 2013 5:28:08 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 635 ms Jul 9, 2013 5:28:08 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Jul 9, 2013 5:28:08 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.35 Jul 9, 2013 5:28:08 PM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive C:\apache-tomcat-7.0.35\webapps\activemq-web-console-5.8.0.war SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/apache-tomcat-7.0.35/webapps/activemq-web-console-5.8.0/WEB-INF/lib/activemq-all-5.8.0.jar!/org/slf4j/impl/Stati cLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/apache-tomcat-7.0.35/webapps/activemq-web-console-5.8.0/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/Stat icLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 2013-07-09 17:28:13,389 [ost-startStop-1] INFO WebConsoleStarter - Web console type: properties 2013-07-09 17:28:13,960 [ost-startStop-1] INFO WebConsoleStarter - ActiveMQ WebConsole initialized. 2013-07-09 17:28:14,095 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/createDestination.action] onto handler '/createDest ination.action' 2013-07-09 17:28:14,096 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteDestination.action] onto handler '/deleteDest ination.action' 2013-07-09 17:28:14,097 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/createSubscriber.action] onto handler '/createSubsc riber.action' 2013-07-09 17:28:14,098 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteSubscriber.action] onto handler '/deleteSubsc riber.action' 2013-07-09 17:28:14,099 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/sendMessage.action] onto handler '/sendMessage.acti on' 2013-07-09 17:28:14,100 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/purgeDestination.action] onto handler '/purgeDestin ation.action' 2013-07-09 17:28:14,101 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteMessage.action] onto handler '/deleteMessage. action' 2013-07-09 17:28:14,103 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/copyMessage.action] onto handler '/copyMessage.acti on' 2013-07-09 17:28:14,104 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/moveMessage.action] onto handler '/moveMessage.acti on' 2013-07-09 17:28:14,105 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteJob.action] onto handler '/deleteJob.action' Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\docs Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\examples Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\host-manager Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\manager Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\ROOT Jul 9, 2013 5:28:14 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] Jul 9, 2013 5:28:14 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 6642 ms Let’s access the web console: http://localhost:8080/activemq-web-console-5.8.0 Use admin/admin for username/password if prompted. These are default security settings. Refer jetty.xml and jetty-realm.properties in conf directory.As shown above, “broker-1″ is the current master broker. Now, if you were to shutdown broker-1. Hit Control+C on Terminal window running broker-1, you’d notice that broker-2 acquires the lock and becomes the master. INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked. INFO | KahaDB is version 4 INFO | Recovering from the journal ... INFO | Recovery replayed 2 operations from the journal in 0.022 seconds. INFO | Apache ActiveMQ 5.8.0 (broker-2, ID:AKUNTAMU-1-28147-1373409767675-0:1) is starting INFO | Listening for connections at: tcp://AKUNTAMU-1:61626?maximumConnections=1000&wireformat.maxFrameSize=104857600 INFO | Connector openwire Started INFO | Apache ActiveMQ 5.8.0 (broker-2, ID:AKUNTAMU-1-28147-1373409767675-0:1) started INFO | For help or more information please see: http://activemq.apache.org WARN | Store limit is 102400 mb, whilst the data directory: C:\apache-activemq-5.8.0\data\kahadb only has 38888 mb of usable space ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\apache-activemq-5.8.0\data\broker-2\tmp_storage only has 38888 mb o f usable space INFO | Web console type: embedded INFO | ActiveMQ WebConsole initialized. INFO | Initializing Spring FrameworkServlet 'dispatcher' INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.xml, access to all MBeans is allowed Let’s refresh the web consoleAs you may observe, now the master node is broker-2. Now that we have seen seamless switch over between the nodes during a failover scenario using an external web console, let’s see the same from the perspective of a message producer and consumer. I will publish 50 persistent messages to a queue using a simple message publisher and have an asynchronous consumer receive those 50 messages. I will introduce a bit of a delay in sending the messages so we can take the master down a few times and create a few failover scenarios. The objective is to see how the failover protocol makes the node failover completely transparent and thus shields the application from having to deal with any reconnection logic. Here is a simple producer using ActiveMQConnectionFactory with failover protocol. Notice the highlighted failover protocol URL in the code snippet below. package com.akuntamukkala.amqms; import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.log4j.Logger; public class Producer { private static final Logger log = Logger.getLogger(Producer.class); public static void main(String[] args) throws Exception { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "failover:(tcp://localhost:61616,tcp://localhost:61626)"); for (int i = 0; i < 50; i++) { log.info("Establishing connection"); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start(); log.info("Connection established"); // Create a Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); // Create a messages String text = "Message Counter : " + i; TextMessage message = session.createTextMessage(text); log.info("Sending message : " + text); producer.send(message); log.info("Sent message : " + text); // Clean up session.close(); connection.close(); Thread.sleep(1000); } } } Here are the logs from execution while I shutdown broker-1 and broker-2 alternatively a few times. 2013-07-10 11:26:32 INFO Producer:25 - Establishing connection 2013-07-10 11:26:33 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:33 INFO Producer:30 - Connection established 2013-07-10 11:26:33 INFO Producer:47 - Sending message : Message Counter : 0 2013-07-10 11:26:33 INFO Producer:49 - Sent message : Message Counter : 0 2013-07-10 11:26:34 INFO Producer:25 - Establishing connection 2013-07-10 11:26:35 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:35 INFO Producer:30 - Connection established 2013-07-10 11:26:35 INFO Producer:47 - Sending message : Message Counter : 1 2013-07-10 11:26:35 INFO Producer:49 - Sent message : Message Counter : 1 2013-07-10 11:26:35 INFO Producer:25 - Establishing connection 2013-07-10 11:26:36 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:36 INFO Producer:30 - Connection established 2013-07-10 11:26:36 INFO Producer:47 - Sending message : Message Counter : 2 2013-07-10 11:26:36 INFO Producer:49 - Sent message : Message Counter : 2 2013-07-10 11:26:37 INFO Producer:25 - Establishing connection 2013-07-10 11:26:37 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:37 INFO Producer:30 - Connection established 2013-07-10 11:26:37 INFO Producer:47 - Sending message : Message Counter : 3 2013-07-10 11:26:37 INFO Producer:49 - Sent message : Message Counter : 3 2013-07-10 11:26:37 INFO Producer:25 - Establishing connection 2013-07-10 11:26:38 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:38 INFO Producer:30 - Connection established 2013-07-10 11:26:38 INFO Producer:47 - Sending message : Message Counter : 4 2013-07-10 11:26:38 INFO Producer:49 - Sent message : Message Counter : 4 2013-07-10 11:26:39 INFO Producer:25 - Establishing connection 2013-07-10 11:26:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:39 INFO Producer:30 - Connection established 2013-07-10 11:26:39 INFO Producer:47 - Sending message : Message Counter : 5 2013-07-10 11:26:39 INFO Producer:49 - Sent message : Message Counter : 5 2013-07-10 11:26:39 INFO Producer:25 - Establishing connection 2013-07-10 11:26:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:39 INFO Producer:30 - Connection established 2013-07-10 11:26:39 INFO Producer:47 - Sending message : Message Counter : 6 2013-07-10 11:26:39 INFO Producer:49 - Sent message : Message Counter : 6 2013-07-10 11:26:40 INFO Producer:25 - Establishing connection 2013-07-10 11:26:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:40 INFO Producer:30 - Connection established 2013-07-10 11:26:40 INFO Producer:47 - Sending message : Message Counter : 7 2013-07-10 11:26:40 INFO Producer:49 - Sent message : Message Counter : 7 2013-07-10 11:26:40 INFO Producer:25 - Establishing connection 2013-07-10 11:26:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:40 INFO Producer:30 - Connection established 2013-07-10 11:26:40 INFO Producer:47 - Sending message : Message Counter : 8 2013-07-10 11:26:40 INFO Producer:49 - Sent message : Message Counter : 8 2013-07-10 11:26:41 INFO Producer:25 - Establishing connection 2013-07-10 11:26:41 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:41 INFO Producer:30 - Connection established 2013-07-10 11:26:41 INFO Producer:47 - Sending message : Message Counter : 9 2013-07-10 11:26:41 INFO Producer:49 - Sent message : Message Counter : 9 2013-07-10 11:26:41 INFO Producer:25 - Establishing connection 2013-07-10 11:26:41 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:41 INFO Producer:30 - Connection established 2013-07-10 11:26:41 INFO Producer:47 - Sending message : Message Counter : 10 2013-07-10 11:26:41 INFO Producer:49 - Sent message : Message Counter : 10 2013-07-10 11:26:42 INFO Producer:25 - Establishing connection 2013-07-10 11:26:43 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:43 INFO Producer:30 - Connection established 2013-07-10 11:26:43 INFO Producer:47 - Sending message : Message Counter : 11 2013-07-10 11:26:43 INFO Producer:49 - Sent message : Message Counter : 11 2013-07-10 11:26:43 INFO Producer:25 - Establishing connection 2013-07-10 11:26:43 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:43 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:26:50 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:26:50 INFO Producer:30 - Connection established 2013-07-10 11:26:50 INFO Producer:47 - Sending message : Message Counter : 12 2013-07-10 11:26:50 INFO Producer:49 - Sent message : Message Counter : 12 2013-07-10 11:26:51 INFO Producer:25 - Establishing connection 2013-07-10 11:26:52 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:52 INFO Producer:30 - Connection established 2013-07-10 11:26:52 INFO Producer:47 - Sending message : Message Counter : 13 2013-07-10 11:26:52 INFO Producer:49 - Sent message : Message Counter : 13 2013-07-10 11:26:52 INFO Producer:25 - Establishing connection 2013-07-10 11:26:53 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:53 INFO Producer:30 - Connection established 2013-07-10 11:26:53 INFO Producer:47 - Sending message : Message Counter : 14 2013-07-10 11:26:53 INFO Producer:49 - Sent message : Message Counter : 14 2013-07-10 11:26:54 INFO Producer:25 - Establishing connection 2013-07-10 11:26:54 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:54 INFO Producer:30 - Connection established 2013-07-10 11:26:54 INFO Producer:47 - Sending message : Message Counter : 15 2013-07-10 11:26:54 INFO Producer:49 - Sent message : Message Counter : 15 2013-07-10 11:26:54 INFO Producer:25 - Establishing connection 2013-07-10 11:26:55 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:55 INFO Producer:30 - Connection established 2013-07-10 11:26:55 INFO Producer:47 - Sending message : Message Counter : 16 2013-07-10 11:26:55 INFO Producer:49 - Sent message : Message Counter : 16 2013-07-10 11:26:56 INFO Producer:25 - Establishing connection 2013-07-10 11:26:57 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:57 INFO Producer:30 - Connection established 2013-07-10 11:26:57 INFO Producer:47 - Sending message : Message Counter : 17 2013-07-10 11:26:57 INFO Producer:49 - Sent message : Message Counter : 17 2013-07-10 11:26:57 INFO Producer:25 - Establishing connection 2013-07-10 11:26:58 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:58 INFO Producer:30 - Connection established 2013-07-10 11:26:58 INFO Producer:47 - Sending message : Message Counter : 18 2013-07-10 11:26:58 INFO Producer:49 - Sent message : Message Counter : 18 2013-07-10 11:26:59 INFO Producer:25 - Establishing connection 2013-07-10 11:26:59 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:59 INFO Producer:30 - Connection established 2013-07-10 11:26:59 INFO Producer:47 - Sending message : Message Counter : 19 2013-07-10 11:26:59 INFO Producer:49 - Sent message : Message Counter : 19 2013-07-10 11:26:59 INFO Producer:25 - Establishing connection 2013-07-10 11:26:59 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:59 INFO Producer:30 - Connection established 2013-07-10 11:26:59 INFO Producer:47 - Sending message : Message Counter : 20 2013-07-10 11:26:59 INFO Producer:49 - Sent message : Message Counter : 20 2013-07-10 11:27:00 INFO Producer:25 - Establishing connection 2013-07-10 11:27:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:01 INFO Producer:30 - Connection established 2013-07-10 11:27:01 INFO Producer:47 - Sending message : Message Counter : 21 2013-07-10 11:27:01 INFO Producer:49 - Sent message : Message Counter : 21 2013-07-10 11:27:01 INFO Producer:25 - Establishing connection 2013-07-10 11:27:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:01 INFO Producer:30 - Connection established 2013-07-10 11:27:01 INFO Producer:47 - Sending message : Message Counter : 22 2013-07-10 11:27:01 INFO Producer:49 - Sent message : Message Counter : 22 2013-07-10 11:27:02 INFO Producer:25 - Establishing connection 2013-07-10 11:27:02 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:02 INFO Producer:30 - Connection established 2013-07-10 11:27:02 INFO Producer:47 - Sending message : Message Counter : 23 2013-07-10 11:27:02 INFO Producer:49 - Sent message : Message Counter : 23 2013-07-10 11:27:02 INFO Producer:25 - Establishing connection 2013-07-10 11:27:02 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:02 INFO Producer:30 - Connection established 2013-07-10 11:27:02 INFO Producer:47 - Sending message : Message Counter : 24 2013-07-10 11:27:02 INFO Producer:49 - Sent message : Message Counter : 24 2013-07-10 11:27:03 INFO Producer:25 - Establishing connection 2013-07-10 11:27:03 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:03 INFO Producer:30 - Connection established 2013-07-10 11:27:03 INFO Producer:47 - Sending message : Message Counter : 25 2013-07-10 11:27:03 INFO Producer:49 - Sent message : Message Counter : 25 2013-07-10 11:27:03 INFO Producer:25 - Establishing connection 2013-07-10 11:27:03 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:03 INFO Producer:30 - Connection established 2013-07-10 11:27:03 INFO Producer:47 - Sending message : Message Counter : 26 2013-07-10 11:27:03 INFO Producer:49 - Sent message : Message Counter : 26 2013-07-10 11:27:04 INFO Producer:25 - Establishing connection 2013-07-10 11:27:04 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:06 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61626) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:27:15 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61616 2013-07-10 11:27:15 INFO Producer:30 - Connection established 2013-07-10 11:27:15 INFO Producer:47 - Sending message : Message Counter : 27 2013-07-10 11:27:15 INFO Producer:49 - Sent message : Message Counter : 27 2013-07-10 11:27:16 INFO Producer:25 - Establishing connection 2013-07-10 11:27:17 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:17 INFO Producer:30 - Connection established 2013-07-10 11:27:17 INFO Producer:47 - Sending message : Message Counter : 28 2013-07-10 11:27:17 INFO Producer:49 - Sent message : Message Counter : 28 2013-07-10 11:27:17 INFO Producer:25 - Establishing connection 2013-07-10 11:27:18 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:18 INFO Producer:30 - Connection established 2013-07-10 11:27:18 INFO Producer:47 - Sending message : Message Counter : 29 2013-07-10 11:27:18 INFO Producer:49 - Sent message : Message Counter : 29 2013-07-10 11:27:19 INFO Producer:25 - Establishing connection 2013-07-10 11:27:20 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:20 INFO Producer:30 - Connection established 2013-07-10 11:27:20 INFO Producer:47 - Sending message : Message Counter : 30 2013-07-10 11:27:20 INFO Producer:49 - Sent message : Message Counter : 30 2013-07-10 11:27:20 INFO Producer:25 - Establishing connection 2013-07-10 11:27:20 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:20 INFO Producer:30 - Connection established 2013-07-10 11:27:20 INFO Producer:47 - Sending message : Message Counter : 31 2013-07-10 11:27:20 INFO Producer:49 - Sent message : Message Counter : 31 2013-07-10 11:27:21 INFO Producer:25 - Establishing connection 2013-07-10 11:27:22 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:22 INFO Producer:30 - Connection established 2013-07-10 11:27:22 INFO Producer:47 - Sending message : Message Counter : 32 2013-07-10 11:27:22 INFO Producer:49 - Sent message : Message Counter : 32 2013-07-10 11:27:22 INFO Producer:25 - Establishing connection 2013-07-10 11:27:22 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:22 INFO Producer:30 - Connection established 2013-07-10 11:27:22 INFO Producer:47 - Sending message : Message Counter : 33 2013-07-10 11:27:22 INFO Producer:49 - Sent message : Message Counter : 33 2013-07-10 11:27:23 INFO Producer:25 - Establishing connection 2013-07-10 11:27:23 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:23 INFO Producer:30 - Connection established 2013-07-10 11:27:23 INFO Producer:47 - Sending message : Message Counter : 34 2013-07-10 11:27:23 INFO Producer:49 - Sent message : Message Counter : 34 2013-07-10 11:27:23 INFO Producer:25 - Establishing connection 2013-07-10 11:27:24 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:24 INFO Producer:30 - Connection established 2013-07-10 11:27:24 INFO Producer:47 - Sending message : Message Counter : 35 2013-07-10 11:27:24 INFO Producer:49 - Sent message : Message Counter : 35 2013-07-10 11:27:25 INFO Producer:25 - Establishing connection 2013-07-10 11:27:27 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:27 INFO Producer:30 - Connection established 2013-07-10 11:27:27 INFO Producer:47 - Sending message : Message Counter : 36 2013-07-10 11:27:27 INFO Producer:49 - Sent message : Message Counter : 36 2013-07-10 11:27:27 INFO Producer:25 - Establishing connection 2013-07-10 11:27:28 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:28 INFO Producer:30 - Connection established 2013-07-10 11:27:28 INFO Producer:47 - Sending message : Message Counter : 37 2013-07-10 11:27:28 INFO Producer:49 - Sent message : Message Counter : 37 2013-07-10 11:27:29 INFO Producer:25 - Establishing connection 2013-07-10 11:27:30 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:30 INFO Producer:30 - Connection established 2013-07-10 11:27:30 INFO Producer:47 - Sending message : Message Counter : 38 2013-07-10 11:27:30 INFO Producer:49 - Sent message : Message Counter : 38 2013-07-10 11:27:30 INFO Producer:25 - Establishing connection 2013-07-10 11:27:31 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:33 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:27:38 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:27:38 INFO Producer:30 - Connection established 2013-07-10 11:27:38 INFO Producer:47 - Sending message : Message Counter : 39 2013-07-10 11:27:38 INFO Producer:49 - Sent message : Message Counter : 39 2013-07-10 11:27:39 INFO Producer:25 - Establishing connection 2013-07-10 11:27:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:39 INFO Producer:30 - Connection established 2013-07-10 11:27:39 INFO Producer:47 - Sending message : Message Counter : 40 2013-07-10 11:27:39 INFO Producer:49 - Sent message : Message Counter : 40 2013-07-10 11:27:39 INFO Producer:25 - Establishing connection 2013-07-10 11:27:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:40 INFO Producer:30 - Connection established 2013-07-10 11:27:40 INFO Producer:47 - Sending message : Message Counter : 41 2013-07-10 11:27:40 INFO Producer:49 - Sent message : Message Counter : 41 2013-07-10 11:27:41 INFO Producer:25 - Establishing connection 2013-07-10 11:27:42 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:42 INFO Producer:30 - Connection established 2013-07-10 11:27:42 INFO Producer:47 - Sending message : Message Counter : 42 2013-07-10 11:27:42 INFO Producer:49 - Sent message : Message Counter : 42 2013-07-10 11:27:42 INFO Producer:25 - Establishing connection 2013-07-10 11:27:42 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:42 INFO Producer:30 - Connection established 2013-07-10 11:27:42 INFO Producer:47 - Sending message : Message Counter : 43 2013-07-10 11:27:42 INFO Producer:49 - Sent message : Message Counter : 43 2013-07-10 11:27:43 INFO Producer:25 - Establishing connection 2013-07-10 11:27:44 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:44 INFO Producer:30 - Connection established 2013-07-10 11:27:44 INFO Producer:47 - Sending message : Message Counter : 44 2013-07-10 11:27:44 INFO Producer:49 - Sent message : Message Counter : 44 2013-07-10 11:27:44 INFO Producer:25 - Establishing connection 2013-07-10 11:27:45 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:45 INFO Producer:30 - Connection established 2013-07-10 11:27:45 INFO Producer:47 - Sending message : Message Counter : 45 2013-07-10 11:27:45 INFO Producer:49 - Sent message : Message Counter : 45 2013-07-10 11:27:46 INFO Producer:25 - Establishing connection 2013-07-10 11:27:47 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:47 INFO Producer:30 - Connection established 2013-07-10 11:27:47 INFO Producer:47 - Sending message : Message Counter : 46 2013-07-10 11:27:47 INFO Producer:49 - Sent message : Message Counter : 46 2013-07-10 11:27:48 INFO Producer:25 - Establishing connection 2013-07-10 11:27:48 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:48 INFO Producer:30 - Connection established 2013-07-10 11:27:48 INFO Producer:47 - Sending message : Message Counter : 47 2013-07-10 11:27:48 INFO Producer:49 - Sent message : Message Counter : 47 2013-07-10 11:27:48 INFO Producer:25 - Establishing connection 2013-07-10 11:27:49 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:49 INFO Producer:30 - Connection established 2013-07-10 11:27:49 INFO Producer:47 - Sending message : Message Counter : 48 2013-07-10 11:27:49 INFO Producer:49 - Sent message : Message Counter : 48 2013-07-10 11:27:50 INFO Producer:25 - Establishing connection 2013-07-10 11:27:51 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:51 INFO Producer:30 - Connection established 2013-07-10 11:27:51 INFO Producer:47 - Sending message : Message Counter : 49 2013-07-10 11:27:51 INFO Producer:49 - Sent message : Message Counter : 49 Here is the web console showing 50 messages enqueued.Don’t bother the #Messages Enqueued = 0 in the above screenshot. This count represents the number of messages enqueued since this node started. Since I had restarted the node after the 50 messages were already enqueued, the count shows as 0. Now lets try to consume these messages using an asynchronous consumer using ActiveMQ connection factory with failover protocol. Here is simple asynchronous consumer with ActiveMQConnectionFactory using failover protocol. package com.akuntamukkala.amqms; import javax.jms.Connection; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.log4j.Logger; public class Consumer implements MessageListener { private static final Logger log = Logger.getLogger(Consumer.class); public static void main(String[] args) throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "failover:(tcp://localhost:61616,tcp://localhost:61626)"); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start(); // Create a Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue("TEST.FOO"); // Create a MessageConsumer from the Session to the Queue MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new Consumer()); // asynchronous listener Thread.sleep(120000); // long wait to keep program running consumer.close(); session.close(); connection.close(); } /** * asynchronous message listener */ public void onMessage(Message message) { try { log.info(((TextMessage) message).getText()); Thread.sleep(500); } catch (JMSException e) { log.error(e); } catch (InterruptedException e) { log.error(e); } } } Here are the logs from the execution. I switched the master nodes a few times as evident in the logs. 2013-07-10 11:46:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:46:01 INFO Consumer:49 - Message Counter : 0 2013-07-10 11:46:02 INFO Consumer:49 - Message Counter : 1 2013-07-10 11:46:02 INFO Consumer:49 - Message Counter : 2 2013-07-10 11:46:03 INFO Consumer:49 - Message Counter : 3 2013-07-10 11:46:03 INFO Consumer:49 - Message Counter : 4 2013-07-10 11:46:04 INFO Consumer:49 - Message Counter : 5 2013-07-10 11:46:04 INFO Consumer:49 - Message Counter : 6 2013-07-10 11:46:05 INFO Consumer:49 - Message Counter : 7 2013-07-10 11:46:05 INFO Consumer:49 - Message Counter : 8 2013-07-10 11:46:06 INFO Consumer:49 - Message Counter : 9 2013-07-10 11:46:06 INFO Consumer:49 - Message Counter : 10 2013-07-10 11:46:07 INFO Consumer:49 - Message Counter : 11 2013-07-10 11:46:07 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.io.EOFException, attempting to automatically reconnect 2013-07-10 11:46:18 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:46:18 WARN ActiveMQMessageConsumer:1348 - Duplicate dispatch on connection: ID:AKUNTAMU-1-2141-1373474760280-1:1 to consumer: ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, ignoring (auto acking) duplicate: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, destination = queue://TEST.FOO, message = ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:AKUNTAMU-1-1739-1373473592152-1:12:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:AKUNTAMU-1-1739-1373473592152-1:12:1:1, destination = queue://TEST.FOO, transactionId = null, expiration = 0, timestamp = 1373473603281, arrival = 0, brokerInTime = 1373473603281, brokerOutTime = 1373474778676, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = Message Counter : 11}, redeliveryCounter = 0} 2013-07-10 11:46:18 INFO Consumer:49 - Message Counter : 12 2013-07-10 11:46:19 INFO Consumer:49 - Message Counter : 13 2013-07-10 11:46:19 INFO Consumer:49 - Message Counter : 14 2013-07-10 11:46:20 INFO Consumer:49 - Message Counter : 15 2013-07-10 11:46:20 INFO Consumer:49 - Message Counter : 16 2013-07-10 11:46:21 INFO Consumer:49 - Message Counter : 17 2013-07-10 11:46:21 INFO Consumer:49 - Message Counter : 18 2013-07-10 11:46:22 INFO Consumer:49 - Message Counter : 19 2013-07-10 11:46:22 INFO Consumer:49 - Message Counter : 20 2013-07-10 11:46:23 INFO Consumer:49 - Message Counter : 21 2013-07-10 11:46:23 INFO Consumer:49 - Message Counter : 22 2013-07-10 11:46:24 INFO Consumer:49 - Message Counter : 23 2013-07-10 11:46:24 INFO Consumer:49 - Message Counter : 24 2013-07-10 11:46:25 INFO Consumer:49 - Message Counter : 25 2013-07-10 11:46:25 INFO Consumer:49 - Message Counter : 26 2013-07-10 11:46:26 INFO Consumer:49 - Message Counter : 27 2013-07-10 11:46:26 INFO Consumer:49 - Message Counter : 28 2013-07-10 11:46:27 INFO Consumer:49 - Message Counter : 29 2013-07-10 11:46:27 INFO Consumer:49 - Message Counter : 30 2013-07-10 11:46:28 INFO Consumer:49 - Message Counter : 31 2013-07-10 11:46:28 INFO Consumer:49 - Message Counter : 32 2013-07-10 11:46:29 INFO Consumer:49 - Message Counter : 33 2013-07-10 11:46:29 INFO Consumer:49 - Message Counter : 34 2013-07-10 11:46:30 INFO Consumer:49 - Message Counter : 35 2013-07-10 11:46:30 INFO Consumer:49 - Message Counter : 36 2013-07-10 11:46:31 INFO Consumer:49 - Message Counter : 37 2013-07-10 11:46:31 INFO Consumer:49 - Message Counter : 38 2013-07-10 11:46:32 INFO Consumer:49 - Message Counter : 39 2013-07-10 11:46:32 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61626) failed, reason: java.io.EOFException, attempting to automatically reconnect 2013-07-10 11:46:43 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61616 2013-07-10 11:46:43 WARN ActiveMQMessageConsumer:1348 - Duplicate dispatch on connection: ID:AKUNTAMU-1-2141-1373474760280-1:1 to consumer: ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, ignoring (auto acking) duplicate: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, destination = queue://TEST.FOO, message = ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:AKUNTAMU-1-1739-1373473592152-1:40:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:AKUNTAMU-1-1739-1373473592152-1:40:1:1, destination = queue://TEST.FOO, transactionId = null, expiration = 0, timestamp = 1373473658595, arrival = 0, brokerInTime = 1373473658599, brokerOutTime = 1373474803745, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = Message Counter : 39}, redeliveryCounter = 0} 2013-07-10 11:46:43 INFO Consumer:49 - Message Counter : 40 2013-07-10 11:46:44 INFO Consumer:49 - Message Counter : 41 2013-07-10 11:46:44 INFO Consumer:49 - Message Counter : 42 2013-07-10 11:46:45 INFO Consumer:49 - Message Counter : 43 2013-07-10 11:46:45 INFO Consumer:49 - Message Counter : 44 2013-07-10 11:46:46 INFO Consumer:49 - Message Counter : 45 2013-07-10 11:46:46 INFO Consumer:49 - Message Counter : 46 2013-07-10 11:46:47 INFO Consumer:49 - Message Counter : 47 2013-07-10 11:46:47 INFO Consumer:49 - Message Counter : 48 2013-07-10 11:46:48 INFO Consumer:49 - Message Counter : 49 Let’s check out the ActiveMQ web console:You may find the # Messages Dequeued = 11 very interesting. This is the number of messages dequeued from the current ActiveMQ master node since it started. Conclusion We have thus seen the following in action:Run 2 ActiveMQ nodes in a Master/Slave configuration with a shared KahaDB file based database. Configure ActiveMQ web console hosted in a Tomcat instance to point to whichever node is Master node in the cluster Failover scenario Message publisher and consumer behavior oblivious to the failoverIn future blogs, I will post some other interesting ActiveMQ configurations. Stay tuned. Happy ActiveMQ’ing! Resources:http://activemq.apache.org/ http://www.jakubkorab.net/category/technology/activemqReference: Using ActiveMQ – “Master/Slave” configuration with failover protocol from our JCG partner Ashwini Kuntamukkala at the Ashwini Kuntamukkala – Technology Enthusiast blog....
apache-activemq-logo

Temp, Store and Memory Percent Usage in ActiveMQ

(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629802223740065"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));In order to effectively use ActiveMQ, it is very important to understand how ActiveMQ manages memory and disk resources to handle non-persistent and persistent messages. ActiveMQ has three key parameters which need to be kept under check.Temp Percent UsageThis is the % of assigned disk storage that has been used up to spool non-persistent messages Non persistent messages are those that don’t survive broker restartStore Percent UsageThis is the % of assigned disk space that has been used up to store persistent messagesMemory Percent UsageThis is the % of assigned memory of the broker that has been used up to keep track of destinations, cache messages etc. This value needs to be lesser than -Xmx  (Max JVM heap size)This blog attempts to clarify how store,temp and memory % usage of a single node ActiveMQ broker instance are calculated. We are using ActiveMQ version 5.8.0 for this explanation. Once we gain clarity on how ActiveMQ operates these values, we can fine tune ActiveMQ using key configuration settings in order to handle the following use cases.Large number of destinations (queues/topics)The destinations could be created/deleted as neededSlow consumersThis is huge issue when consumers are unable to keep up with the rate at which messages are being produced.Message BurstRapid influx of large number of messages with huge payload size for a brief period of timeInappropriate Resource utilizationFew destinations chewing up resources causing others to starveScaling Strategies If you are interested to know how ActiveMQ can be scaled horizontally, please refer to a slide deck created by Bosanac Dejan. You can find it here It contains different ActiveMQ topologies which can be used effectively to meet volume throughput in addition to various parameters to tune ActiveMQ. I found it extremely useful. Let’s dig right in… The following XML snippet is taken from configuration activemq.xml. The values specified for memoryUsage, storeUsage and tempUsage are for discussion purposes only. <systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="256 mb"/> </memoryUsage> <storeUsage> <storeUsage limit="512 mb"/> </storeUsage> <tempUsage> <tempUsage limit="256 mb"/> </tempUsage> </systemUsage> </systemUsage>Memory Usage256MB of JVM memory is available for the broker. Not to be confused with -Xmx parameter.Store Usage:This is the disk space used by persistent messages (using KahaDB)Temp Usage:This is the disk space used by non-persistent message, assuming we are using default KahaDB. ActiveMQ spools non-persistent messages to disk in order to prevent broker running out of memoryUnderstanding Temp Usage Broker availability is critical for message infrastructure. Hence producer flow control is a protection mechanism that prevents a runaway producer from pumping non-persistent messages into a destination when there are no consumers or when consumer(s) is unable to keep up with the rate at which messages are being produced into the destination. Let’s take an example of producing non-persistent messages having 1MB payload size into a destination “foo.bar” in a local broker instance C:\apache-activemq-5.8.0\example>ant producer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar -Ddurable=false -DmessageSize=1048576 The producer eventually hangs as temp % usage hits 100%Since the messages are non-persistent, they are going to be stored in tmp_storage on the diskActiveMQ provides mechanism to tune memory usage per destination. Here we have a generic policy for all queues where producer flow control is enabled and destination memory limit is 100MB (again this is only for illustration purposes). <policyEntry queue=">" optimizedDispatch="true" producerFlowControl="true" cursorMemoryHighWaterMark="30" memoryLimit="100 mb" > The temp % usage is calculated as follows: (Size of the tmp_storage folder / temp usage memory limit ) * 100 So in our case: 265,025,856/(256*1024*1024) * 100 = 99.8 ~ 100% as shown in the broker console. The following log message shows up in activemq.log INFO | Usage(default:temp:queue://foo.bar:temp) percentUsage=99%, usage=268535808, limit=268435456, percentUsageMinDelta=1%;Parent:Usage(default:temp ) percentUsage=100%, usage=268535808, limit=268435456, percentUsageMinDelta=1%: Temp Store is Full (99% of 268435456). Stopping producer (ID:AKUNTAMU- 1-61270-1388528939599-1:1:1:1) to prevent flooding queue://foo.bar. See http://activemq.apache.org/producer-flow-control.html for more info (blockingfor: 1421s) Let’s take another example… Consider the following system usage configuration. We have reduced tempUsage to 50MB while keeping the same destination level policy. <systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="256 mb"/> </memoryUsage> <storeUsage> <storeUsage limit="512 mb"/> </storeUsage> <tempUsage> <tempUsage limit="50 mb"/> </tempUsage> </systemUsage></systemUsage> In this case we find that temp usage balloons to 191%temp_storage stops growing at close to 96MB and producer hangs..Temp percent usage is 191% because (95.5MB / 50 MB)*100 where 95.5 MB is size of the folder and 50MB is temp usage limit. The destination has a limit of 100MB so the temp_storage didn’t grow past it. It is sort of confusing which is caused by the fact that temp usage limit is less that per destination memory limit. Store Usage Let’s repeat the same test with persistent messages. The system usage is configured as follows: <systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="256 mb"/> </memoryUsage> <storeUsage> <storeUsage limit="512 mb"/> </storeUsage> <tempUsage> <tempUsage limit="256 mb"/> </tempUsage> </systemUsage></systemUsage>Per destination policy is as follows: <policyEntry queue=">" optimizedDispatch="true" producerFlowControl="true" cursorMemoryHighWaterMark="30" memoryLimit="100 mb" >Let’s produce 1MB persistent messages into a queue named “foo.bar” C:\apache-activemq-5.8.0\example>ant producer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar -Ddurable=true -DmessageSize=1048576Producer hangs after 512 messages The following log statement appears in broker log file INFO | Usage(default:store:queue://foo.bar:store) percentUsage=99%, usage=537210471, limit=536870912, percentUsageMinDelta=1%;Parent:Usage(default:st ore) percentUsage=100%, usage=537210471, limit=536870912,percentUsageMinDelta=1%: Persistent store is Full, 100% of 536870912. Stopping producer (ID: AKUNTAMU-1-31754-1388571228628-1:1:1:1) to prevent flooding queue://foo.bar. See http://activemq.apache.org/producer-flow-control.html for more info ( blocking for: 155s) Broker store usage is 100% as shown below.Since the messages are persistent, they need to be saved onto the file system. Store usage limit is 512MB.The above screenshot shows the kahadb folder where persistent messages is 543 MB (512MB for the messages and other database related files) Memory Usage In the above example, the memory usage percentage is 11. How did that come about? As per the destination policy, the memory allocated per destination is 100MB and the cursorMemoryHighWaterMark is specified to be 30. So 30% of 100MB is 30MB. Hence 30MB is used to store messages in memory for faster processing in addition to be being stored in the KahaDB. . The memory usage limit is configured to be 256MB. So 30MB is ~ 11% of 256 (30/256) * 100 ~ 11% So if we were to have 9 such queues where similar situation was to occur then we would have exhausted broker memory usage as 11 % * 9 = 99% ~ 100% Memory usage is the amount of memory used by the broker for storing messages. Many a times, this can become a bottleneck as once this space is full, the broker will stall the producers.  There are trade-offs between fast processing and effective memory management. If we keep more messages in memory, the processing is faster. However the memory consumption will be very high. On the contrary, if messages are kept on the disk then processing will become slow. Conclusion We have seen in this blog how store, temp and memory usage work in ActiveMQ. % of store and temp usage cannot be configured per destination while % of memory usage can be because of cursorMemoryHighWaterMark. Hope you found this information useful. The examples given here are for explanation purposes only and not meant to be production ready. You will need to do proper capacity planning and determine your broker topology for optimal configuration. Feel free to reach out if any comments! Resourceshttp://blog.raulkr.net/2012/08/demystifying-producer-flow-control-and.html http://tmielke.blogspot.com/2011/02/observations-on-activemqs-temp-storage.html http://activemq.apache.org/javalangoutofmemory.html http://www.slideshare.net/dejanb/advanced-messaging-with-apache-activemq -Bosanac Dejan http://www.pepperdust.org/?p=150 http://stackoverflow.com/questions/2361541/how-do-you-scale-your-activemq-vertically Reference: Temp, Store and Memory Percent Usage in ActiveMQ from our JCG partner Ashwini Kuntamukkala at the Ashwini Kuntamukkala – Technology Enthusiast blog....
Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.