[rabbitmq-discuss] Publish while processing?
emile at rabbitmq.com
Thu Oct 21 15:58:17 BST 2010
On 15/10/10 17:22, Dave Gorman wrote:
> I have a couple messaging scenarios I need help with...
> 1) I would like to have a subscriber listening to "raw" queue; then do
> some preprocessing and publish a new message, such as "preprocessed" to
> the same exchange.
> 2) I would also like to have a subscriber that would process and push to
> a different exchange.
> I noticed in the .Net Client User Guide that it says do not call
> .basicPublish during a callback as it blocks threads.
> using (IConnection conn = connectionFactory.CreateConnection())
> using (IModel model = conn.CreateModel())
> var sub = new Subscription(model, "rtls");
> foreach (BasicDeliverEventArgs iter in sub)
> var message = System.Text.Encoding.UTF8.GetString(iter.Body);
> //want to crunch and publish to different exchange or same
> // ***.BasicPublish(...);
> I would like to successfully process and publish the new message before
> I send the ack() on the original message; just so I'm sure every message
> is processed.
> Is this the proper way to process or will that cause threading issues?
When using Subscription the threading issues warned about in the user
guide do not arise, because callbacks are not invoked from the
connection thread. Subscription makes use of QueueingBasicConsumer
internally and prevents a deadline scenario.
You should therefore be able to replace "***" with "model" in your
More information about the rabbitmq-discuss