You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by zielin <pa...@zielin.pl> on 2013/12/13 09:29:42 UTC

ActiveMQ sync consumers in threads

Hello,

I'm writing library in QT C++ which wraps ActiveMQ CMS API and allows using
activemq without including any cms api headers etc. I have written
synchronous consumer and producer. Everything works fine until I create two
synchronous consumers consuming messages in separate threads. For example:
    Consumer c1;
    c1.topic = "test";
    c1.start(); -- starts thread 1

    c1.sleep(2);

    Consumer c2;
    c2.topic = "test2";
    c2.start(); -- starts thread 2

Code above should create two consumers working separately in threads, but in
the end, works only c2, and it can consume messages. Consumer c1 is totally
suspended and never exits from cms::MessageConsumer::receive method.

Consumers are created in threads, they doesn't share sessions. I haven't
implemented consumers as messagelisteners because I wanted to avoid
including ActiveMQ header files in my declaration file. I want to create
fully functional library for QT which allows using activemq. It works fine
for one consumer :/.

Can You help me solve problem of locked first consumer? Is there possibility
using synchronous consumers in separated threads independently ?

Thanks. 



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-sync-consumers-in-threads-tp4675514.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: ActiveMQ sync consumers in threads

Posted by zielin <pa...@zielin.pl>.
Thanks for reply.

I'm not sure, but problem seems to be resolved. I've moved call of
activemq::library::ActiveMQCPP::initializeLibrary() into static wrapper
method which user can call only once. I'm calling it from main function.
When activemq::library::ActiveMQCPP::initializeLibrary() was called during
every session initialization the problem occured. I thought that if it is
static, it could be called from any context any times. I must check it to be
sure that it was problem.

Now QT wrapper for ActiveMQ works pretty good. I've made async consumer and
producer(sends messages from internal list in separate thread).

Greetings.




--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-sync-consumers-in-threads-tp4675514p4675608.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: ActiveMQ sync consumers in threads

Posted by Timothy Bish <ta...@gmail.com>.
On 12/13/2013 03:29 AM, zielin wrote:
> Hello,
>
> I'm writing library in QT C++ which wraps ActiveMQ CMS API and allows using
> activemq without including any cms api headers etc. I have written
> synchronous consumer and producer. Everything works fine until I create two
> synchronous consumers consuming messages in separate threads. For example:
>      Consumer c1;
>      c1.topic = "test";
>      c1.start(); -- starts thread 1
>
>      c1.sleep(2);
>
>      Consumer c2;
>      c2.topic = "test2";
>      c2.start(); -- starts thread 2
>
> Code above should create two consumers working separately in threads, but in
> the end, works only c2, and it can consume messages. Consumer c1 is totally
> suspended and never exits from cms::MessageConsumer::receive method.
>
> Consumers are created in threads, they doesn't share sessions. I haven't
> implemented consumers as messagelisteners because I wanted to avoid
> including ActiveMQ header files in my declaration file. I want to create
> fully functional library for QT which allows using activemq. It works fine
> for one consumer :/.
>
> Can You help me solve problem of locked first consumer? Is there possibility
> using synchronous consumers in separated threads independently ?
>
> Thanks.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-sync-consumers-in-threads-tp4675514.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>
There's no known issue with using two consumers that I'm aware of. I'd 
take a look at your QT code and ensure you don't have and issue there 
first, or get back to basics and try implementing the CMS code to do 
what you want first and then abstract it to the QT library you are 
writing.  One thing to be aware of is consumer prefetch, is one consumer 
is hogging all the messages in its prefetch buffer your second one 
wouldn't be able to receive anything until enough messages are produced.

-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/