Can you publish a message while processing a queue in RabbitMQ .Net Client?


I have a couple messaging scenarios I need help with using RabbitMQ 2.1.0 in c#... 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) similar to 1 but publish 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); //do stuff and build up a new message //possibly create a new connection? // ***.BasicPublish(new message); sub.Ack(iter); } } }

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 it cause threading issues?

Thank you for your help!


What you say about callbacks is true, but it only applies if you're subclassing DefaultBasicConsumer (or writing your own consumer from scratch).

In your case, Subscription is the consumer and it shouldn't cause any locks by itself. The code you have is fine, since it only uses the Subscription consumer. It should be safe to BasicPublish at that point.

Your code also happens to be (more or less) our <a href="http://hg.rabbitmq.com/rabbitmq-dotnet-client/file/7250b2ec6722/projects/examples/client/Subscriber/src/examples/Subscriber.cs" rel="nofollow">Subscriber</a> example.

Also, sorry for not answering on rabbitmq-discuss.


  • ActiveMQ delete specific message
  • Send and Receive XML formatted text to IBM WebSphere MQ using XMS
  • How can I recognize ActiveMQ disconnect using NMS and C#
  • Sping .jms.listener blocking another listener from reading JMS message
  • How to declare global NodeJS variables within my ambient declaration file?
  • Hibernate not creating Table automatically in spring boot using postgresql
  • Execute Success but num_rows return 0 [PHP-MySQL]
  • How to export MS Access table into a csv file in Python using e.g. pypyodbc
  • spring arbitrary messaging tcp socket
  • I get the following error when trying to set a wallpaper [duplicate]
  • Android VideoView plays 2 videos at the same time
  • Displaying Data From Multiple MySQL Tables
  • Facebook API: cannot login on Android
  • Api Gateway cannot allow Access-Control-Allow-Origin
  • Trouble Attaching Call Back to Unobtrusive Validation Show Error
  • While loop won't end when I tell it in JavaScript
  • JavaScript overloading with a callback
  • File random access in J2ME
  • How to generate an asynchronous reset verilog always blocks with chisel
  • Netlink sockets and libnl - nl_recvmsgs_default returning -16 (EBUSY)
  • In Akka, is ActorContext thread safe?
  • Graceful pod termination
  • Python function to read variable length blocks of data from file while open
  • Creating a C++ function that calls other Lua function
  • pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?
  • Error in making a socket connection
  • Converting query results into DataFrame in python
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • Defined variables not working in javascript files when I use getScript
  • Can't remove headers after they are sent
  • How to synchronize jQuery dialog box to act like alert() of Javascript
  • Record samples being played with OpenAL
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Spray.io: When (not) to use non-blocking route handling?
  • Confusion with PayPal's monthly billing cycle
  • Transpose CSV data with awk (pivot transformation)
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?