[rabbitmq-discuss] queue subscription + sending to some exchange
Busoli, Simone
Simone.Busoli at ferrari.com
Wed Jun 22 09:44:41 BST 2011
Hi Petar,
looking at the code I am under the impression that you may have a race condition between the subscription and the first publish, in that the second may try to publish to the exchange before the first declares it, although I believed the exchange declaration was a synchronous operation.
Side note: instead of your assertion helpers, you can leverage NUnit's support for delayed (polling) assertions:
Assert.That(() => done, Is.EqualTo(3).After(delay))
NUnit will verify the assertion at intervals until delay has expired, at which point it will fail if the constraint is not satisfied yet.
-----Original Message-----
From: rabbitmq-discuss-bounces at lists.rabbitmq.com [mailto:rabbitmq-discuss-bounces at lists.rabbitmq.com] On Behalf Of Petar Shomov
Sent: Wednesday, June 22, 2011 3:20 AM
To: Emile Joubert
Cc: rabbitmq-discuss at lists.rabbitmq.com
Subject: Re: [rabbitmq-discuss] queue subscription + sending to some exchange
Hi Emile,
What a great suggestion: look into the log file ;). Indeed I looked and found the problem: the exchange I was posting to did not exist.
Somehow the first posting succeeded but on the second attempt did not go through or something like that.
I am going to post the mini-example just in case since I prepared it anyways so it might be useful to someone. I find the error message in the rabbitmq server log very helpful but the one that I got in the client was very confusing - The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=504, text="Frame received for invalid channel 2", classId=0, methodId=0,
cause=RabbitMQ.Client.Impl.ChannelErrorException: Frame received for invalid channel 2
Thank you and Simone for reaching out!
---------------------------------
Regards,
Petar
On Tue, Jun 21, 2011 at 9:40 AM, Emile Joubert <emile at rabbitmq.com> wrote:
> Hi Petar,
>
> I assume that queueHandlers in your snippet establishes a new channel
> when the error occurs. Is it possible that queueHandlers is using the
> wrong channel by mistake? Can you supply a minimal self-contained
> example that illustrates the problem? Is there any additional
> information in the broker logfile at the time of the error?
>
>
> -Emile
>
>
> On 21/06/11 01:17, Petar Shomov wrote:
>> Hi Simone,
>>
>> Thanx for the suggestion! I have read that section about threading
>> many times but my understanding is that channels can be shared among
>> threads as long as they are not used concurrently. I am not doing
>> that and I even went ahead and created that channel in the thread
>> that is doing the consumption just to be on the safe side. No dice,
>> same error.
>>
>> What worries me in that section is this paragraph:
>>
>> "Application callback handlers must not invoke blocking AMQP
>> operations (such as IModel.QueueDeclare, IModel.BasicCancel or
>> IModel.BasicPublish). If they do, the channel will deadlock"
>>
>> Now, does that mean I should not be doing what I intended to be doing
>> (I use IModel.BasicPublish)? I find that hard to believe.
>> I am taking care to open a different channel for the publishing of my
>> messages but I wonder is that enough?
>> My channel did not deadlock just looks like things got mixed up ;(
>>
>> ---------------------------------
>> Regards,
>>
>> Petar
>>
>>
>>
>> On Mon, Jun 20, 2011 at 9:57 PM, Simone Busoli <simone.busoli at gmail.com> wrote:
>>> Hi Petar,
>>>
>>> I think you are violating one of the assumption that the C# client
>>> does on channel usage. Channels should not be shared among threads
>>> (read the pdf user guide for details), and it appears you are using
>>> the channel on a different thread than that where the channel was created.
>>>
>>> On Mon, Jun 20, 2011 at 23:41, Petar Shomov <pshomov at gmail.com> wrote:
>>>>
>>>> Hi guys,
>>>>
>>>> I have a situation which I do not completely understand and I was
>>>> hoping someone more acquainted with AMQP and RabbitMQ might point
>>>> me in the right direction.
>>>>
>>>> I have a console app that needs to subscribe to a message queue
>>>> where the process of handling a message is rather lengthy. During
>>>> this lengthy process I need to send out messages to some exchange
>>>> which represent information about the progress of the operation.
>>>> The subscription to the queue has to be asynchronous too, since I
>>>> am doing something else on the main thread. So I have running in a
>>>> thread this code (C#):
>>>>
>>>> var job = new Thread(() =>
>>>> {
>>>> var consumer = new
>>>> QueueingBasicConsumer(channel);
>>>>
>>>> channel.BasicConsume(queueName, false, consumer);
>>>> while (true)
>>>> {
>>>>
>>>> BasicDeliverEventArgs e = null;
>>>> e =
>>>> (BasicDeliverEventArgs) consumer.Queue.Dequeue();
>>>>
>>>> queueHandlers[queueName][e.Exchange](e);
>>>>
>>>> channel.BasicAck(e.DeliveryTag, false);
>>>> }
>>>> }
>>>>
>>>> Unfortunately when I try to send messages within the message
>>>> handler (I am opening a different channel on the same connection,
>>>> tried even opening a different connection with no better luck) I am
>>>> getting these kind of exceptions, usually when attempting to send
>>>> the *second*
>>>> message:
>>>>
>>>> - $exception {"The AMQP operation was
>>>> interrupted: AMQP close-reason, initiated by Library, code=504,
>>>> text=\"Frame received for invalid channel 2\", classId=0,
>>>> methodId=0,
>>>> cause=RabbitMQ.Client.Impl.ChannelErrorException: Frame received
>>>> for invalid channel 2\r\n at ...
>>>>
>>>>
>>>> Thoughts, ideas, anything?
>
_________________________________________________________________________________________________________________
Questo messaggio è da intendersi esclusivamente ad uso del destinatario e può contenere informazioni che sono di natura privilegiata, confidenziale
o non divulgabile secondo le leggi vigenti. Se il lettore del presente messaggio non è il destinatario designato, o il dipendente/agente responsabile
per la consegna del messaggio al destinatario designato, si informa che ogni disseminazione, distribuzione o copiatura di questa comunicazione è
strettamente proibita anche ai sensi del decreto legislativo 196/03 . Se avete ricevuto questo messaggio per errore, vi preghiamo di notificarcelo
immediatamente a mezzo e-mail di risposta e successivamente di procedere alla cancellazione di questa e-mail e relativi allegati dal vostro sistema.
_________________________________________________________________________________________________________________
This message is intended only for the use of the addressee and may contain information that is privileged, confidential and exempt from
disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the
message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this e-mail in error, please notify us immediately by return e-mail and delete this e-mail and all attachments from
your system.
_________________________________________________________________________________________________________________
More information about the rabbitmq-discuss
mailing list