Thursday, January 15, 2015

ActiveMQ Broker and Spring JMS Integration

I was writing a test case in which I was sending an event through my test case and was allowing the application to listen to that event and then further do the end to end testing.

To start the ActiveMQ in my test cases i was using BrokerService with the url on which my application is listening.After the broker service got started i was sending event immediately.

The problem was that my application was not able to listen to that event.

Sequence was..

1. start spring context of my application ( which use service-activator of spring to listen to event).

2. start broker

3.publish event through my test case.

At that time,I didn't have time to see what's wrong so I put Thread.sleep(10*1000) between step 2 & 3 and my application started to listen to event.

Now today I spent some time finding out the issue.Initially I thought that I am sending message before the broker is even started so I created a main class , started the broker and send the message.But the broker was started before i published the message.

Then what went wrong?

I digged more and placed Thread.sleep above "start broker" and below "start broker" to find out what's really happening.

After going through the logs I found that the spring context listener is somewhat synchronizing with broker that i started which is taking 4-5 seconds..

11:54:07.029 [main] INFO  o.a.activemq.broker.BrokerService - For help or more information please see: http://activemq.apache.org
11:54:07.029 [main] INFO  c.s.c.p.activemq.ActiveMqRunner - Time taken to start broker: 903 millis
11:54:07.029 [main] INFO  c.s.c.p.activemq.ActiveMqRunner - Broker started !!
Jan 16, 2015 11:54:07 AM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [0.0.0.0:8092]
Jan 16, 2015 11:54:07 AM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
11:54:11.138 [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] DEBUG o.a.a.transport.WireFormatNegotiator - Sending: WireFormatInfo { version=9, properties={MaxFrameSize=9223372036854775807, CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=0, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}

 This was the main problem.So i decided to start broker at first step so that all the application context can get in sync with my broker.

Final sequence was:

1. start broker

2. start spring context of my application ( which use service-activator of spring to listen to event).

3. publish event

And my problem got solved ..

Monday, January 5, 2015

SVN or GIT (Know your use case !!)

I am working on project that uses GIT as source code manager.Prior to this I worked on a project that was using SVN. Now everytime I make a commit on to GIT I just wonder why we are using GIT or what is wrong with SVN.In search of answer, I found some really good posts on google.

Ultimately, I came to the conclusion that its your use case that matters.They both are good. Now in which use case you should use what is a question. Here are some of my findings..


  • GIT is decentralized. Which essentially means you can commit to your local machine even when you are not connected to the internet.
Now the question comes, does your projects or team would be frequently in a situation where you dont have internet access!! Is your company is offering you special kind of holidays where you go to the mountains and you have to commit. How often are you going to do that?Just because once in a bluemoon you dont have internet access and you are desperate to commit ( and not wishing to keep your changes in changelist) you are using GIT.Even though you commit, no body would be able to see your changes because you are not connected to internet!! 
Using GIT..
  • GIT is the new cool thing that is trending in the developer fashion space.If your use case is to use version control that is trending..use GIT
We like to follow the latest trend..
  • GIT is well suited when multiple developers are working on different branches and not connected to main branch.(trunk/origin whatever..)
Now, does your project in your company work in this way?If yes then go for git, because git have sophisticated techniques of merging,rebasing,switching between branches. My project however work in a way most projects work.All developers make changes for the upcoming release.We have builds running to ensure nothing gets broken.Then why use GIT??

  • GIT is best suited for open source projects where multiple developers fork a branch and everyone adds a functionality and the owner chooses the best one from several branches and pulls the changes to the main..
In a nutshell, I would like to say if you and your team really needs some kind of offline version control , and you guys can take out time to learn this new system with entirely different terminology ( checkout /clone and commit/push) then go for GIT.And if you are interested in spending more time on delivering performant system and just a version control system that manages source code for you then go for SVN because its very intuitive and easy to use..