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 ..
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 ..
No comments:
Post a Comment