[prev in list] [next in list] [prev in thread] [next in thread] 

List:       activemq-users
Subject:    Re: activemq consumer does not return data even when queue not empty
From:       Tim Bain <tbain98 () gmail ! com>
Date:       2016-02-27 17:40:42
Message-ID: CAPVVMa8SXsEZ0faT=G8d=uv4vWpL_9E9W4UNDXQ_Bn3tFHXUuQ () mail ! gmail ! com
[Download RAW message or body]


Are you hitting your catch block?  Add logging before you re-throw to find
out.

Also, a thread dump could help determine if you're stuck in a blocking call
or bombing out early, though it won't tell you why you bombed out (that's
what the logging in the catch block is for).

What are the queue stats (from JMX or the web console) before and after you
attempt to consume the messages?  What happens if you consume a second
time?  And since you're giving each message an ID, what's the pattern for
which messages get consumed?  Is everything in order, or do you have gaps?

Tim
On Feb 27, 2016 8:20 AM, "vishva" <vishva2005@gmail.com> wrote:

> I wrote a sample code to add elements to activemq, and then retrieve them.
> I
> was successfully able to add around 1000 elements, but while retrieving the
> elements, somehow code gets stuck after retrieving around 50 - 200
> elements,
> even when the queue has a lot of elements.
> 
> Following is the code i used for adding elements to the queue
> 
> @POST
> @Path("/addelementtoqueue")
> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
> public void addElementToQeueue(@FormParam("count") int count) throws
> Exception {
> IntStream.range(0, count)
> .forEach(e -> {
> try {
> addElement(e);
> }catch(Exception e1) {
> throw new RuntimeException(e1);
> }
> });
> }
> 
> private void addElement(int i) throws Exception {
> Connection conn =
> GlobalConfiguration.getJMSConnectionFactory().createConnection();
> conn.start();
> Session session = conn.createSession(false,
> Session.CLIENT_ACKNOWLEDGE);
> MessageProducer prod = session.createProducer(queue);
> prod.send(queue, session.createTextMessage("message "+ i),
> DeliveryMode.PERSISTENT, 4, 0);
> prod.close();
> session.close();
> conn.close();
> }
> and this is the snippet i am using for retrieving elements from the queue
> 
> @POST
> @Path("/removeelementfromqueue")
> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
> public void removeElementToQeueue(@FormParam("count") int count) throws
> Exception {
> IntStream.range(0, count)
> .forEach(e -> {
> try {
> extractElement();
> }catch(Exception e1) {
> throw new RuntimeException(e1);
> }
> });
> }
> 
> private void extractElement() throws Exception {
> Connection conn =
> GlobalConfiguration.getJMSConnectionFactory().createConnection();
> conn.start();
> Session session = conn.createSession(false,
> Session.CLIENT_ACKNOWLEDGE);
> queue = session.createQueue("walkin.testing");
> MessageConsumer consumer = session.createConsumer(queue);
> TextMessage msg = (TextMessage)consumer.receive();
> System.out.println(msg.getText());
> msg.acknowledge();
> consumer.close();
> session.close();
> conn.close();
> }
> I am getting the connection factory via resource.xml, the snippet for the
> same is
> 
> <resources>
> <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
> BrokerXmlConfig = jdbcBroker:(tcp://0.0.0.0:61616)
> ServerUrl       = tcp://
> 0.0.0.0:61616?jms.prefetchPolicy.queuePrefetch=0
> </Resource>
> 
> <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
> ResourceAdapter = MyJmsResourceAdapter
> </Resource></resources>
> I am using activeMQ 5.13.1, with apache-tomee-plus-1.7.2 and Java 8, jdbc
> store as mysql. I have configured activemq-jdbc-performance.xml as the
> configuration file for apache activemq.
> 
> I have tried to a lot of research on this one, but i am unable to identify
> the root cause of this issue. It would be highly helpful, if any one can
> suggest me what i am doing wrong
> 
> 
> 
> 
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/activemq-consumer-does-not-return-data-even-when-queue-not-empty-tp4708474.html
>  Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic