activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@domdv.de
Subject Re: AMQ-CMS - questions about threads/producerthreads in AMQ
Date Fri, 04 Mar 2011 11:46:45 GMT
Thanks for the fast reply.

I already tested a bit with the example. I also think i know how esb and
amq work basically.

The problem is this:

1.) How can I create a Producer-Thread which sleeps until my programm
wants to send a message? And how do I call the function which sends the
message? I tried to do this with sleep() and signaling. But since the
threadID i get is lld and not d it seems i cant send a signal to the
thread. How is this usually done?

2.) As far as i understood, a thread which also derives from
Messagelistener, will sleep if i call "latch.await();". And it will wake
up if a message is on the topic. Does it goes to sleep afterwards?

The problem is that I want to send async messages, which can make their
retry and so on, without blocking my system.
If I use the normal async handling, messages can get lost, which should
never happen for my program. But normal syncron messages would block it. I
guess I'm not the first person with such needs. What is usually done in
such cases?

So i thought that a thread sends the message for me and persists it.

I have, up to the moment, little trouble in developing syncronous messages
between my 2 components. But I would be rellay grateful if someone could
point me to the starting point for async-message handling like I need it.

I hope I could describe my problems good enough so that they are
understandable.

Best regards,
amqBeginner

> I think that if you go to section CMS-API-Overview
>
> http://activemq.apache.org/cms/cms-api-overview.html
>
>
>  <http://activemq.apache.org/cms/example.html>At the end, you could see
> something that is more addaptable for that you want. I think ;-)
>
>
> regards
>
> 2011/3/4 <mzo@domdv.de>
>
>> Hello there,
>>
>> greetings from Germany. ;)
>>
>> I'm currently trying to work myself into AMQ. I already tried several
>> approches to the producer thread question and have searched the web and
>> the
>> forum. I'm also a beginner to the multithreading theme.
>>
>> The situation:
>> I would like my application to create a consumer and a producer, which
>> is
>> no
>> problem. But both should live forever.
>> The consumer sleeps via a Countdownlatch, which will never be count
>> down,
>> and wakes up via a Messagelistener, when a message is recieved.
>> The producer is my main problem. The application tells me to send a
>> message.
>> Now i want to tell my producer thread to send this message syncron with
>> failure handling etc, while my application runs on. How do i tell the
>> thread
>> to wait for a message? How do I tell the threads to live forever?
>>
>> I already thought about using mutexes, semaphores, signals etc. But i
>> found
>> out that the decaf threads already use pthread internally. So i guess
>> there
>> exists functions for my problems, that i haven't found so far.
>>
>> Propably my first trys do something which is way to complex, where there
>> already exists methods or wrapper:
>>
>> I already tried to use signals, but the signal doesn't seems work with
>> the
>> threadID i get from the decaf thread. Eg:
>>
>> Application:
>>
>> this->consumerThread = new Thread(&cmsConsAsync);
>> this->consumerThread->start();
>> cmsConsAsync.waitUntilReady();
>> this->producerThread = new Thread(&cmsProdAsync);
>> this->producerThread->start();
>> cmsProdAsync.waitUntilReady();
>> this->prodThreadID = this->producerThread->getId();
>> printf("PID: %lld\n", this->prodThreadID);
>> printf("State: %d\n", this->producerThread->getState());
>> if (this->producerThread->isAlive())
>>  {
>>      printf("IsAlive\n");
>>      kill(this->prodThreadID, SIGUSR1);
>>      printf("IsAlive2\n");
>>  }
>>  else
>>      printf("I'm killed!\n");
>>
>> The Producer:
>>
>>            /* set function calls */
>>            signal(SIGUSR1, CMSProducer::sendTextMessage);
>>            signal(SIGUSR2, CMSProducer::sendObjMessage);
>>            signal(SIGQUIT, CMSProducer::shutdown);
>>
>>            //let caller run on
>>            latch.countDown();
>>
>>            //set to sleep, will wake up on signal calls
>>            //waitLatch.await();
>>            while(CMSProducer::noQuit)
>>            {
>>                printf("PAUSE!\n");
>>                pause();
>>            }
>>
>> Is there a better way to do something like this?
>>
>> Best regards,
>> amqBeginner
>>
>>
>
>
> --
> Óscar Pernas Plaza.
>





Mime
View raw message