Hello, I have a question regarding the documentation of Consume()
.
Consumers must range over the chan to ensure all deliveries are received. Unreceived deliveries will block all methods on the same connection.
So it's not safe to Publish()
a message when iterating over the chan Delivery
from Consume()
? A unreceived delivery could deadlock the Publish()
.
The only safe way is to have a separate connection for the publisher and the consumer?
Using a different channel for Publish()
would still be unsafe?
In general the protocol in no way prevents you from consuming and publishing on the same channel. If your publishers run into resource alarms it may be a good idea to use separate connections so that consumers can perform other operations (e.g. declare queues or bind them) even an alarm is in effect (consumers are not blocked by alarms in any way when it comes to deliveries).
There can be something specific to this client that must be considered when publishing and consuming on the same connection but I cannot immediately think of anything. @streadway @gerhard do you have anything to add?
@michaelklishin thanks for your reply.
What do you mean with "resource alarms"?
@fho see documentation.
@michaelklishin thanks, I don't think the quoted part from the documentation is about resource alarms.
The quote again:
Consumers must range over the chan to ensure all deliveries are received. Unreceived deliveries will block all methods on the same connection.
Scenario: I have unreceived deliveries in the queue on the server. I'm iterating over the messages from the Delivery channel.
If I would call Publish()
in the loop, I would get a deadlock on all channels of the connection because of the unreceived deliveries?
If not, what is the meaning of the quoted documentation?
I don't see how unconsumed deliveries can block publishes. There is no response to basic.publish
in the protocol.
The comment in question was added in https://github.com/streadway/amqp/commit/962fd418afbeb06747a85b9048a7c70691d672ae 5 years ago. Perhaps @streadway can remember what it was about.
@michaelklishin
If I want to use rabbitMQ connection for multiple goruotine, Should I make each connection for consume and publish? like this?
type rabbitmq struct {
consumeConn *amqp.Connection
publishConn *amqp.Connection
}
or
Is it just ok making channel per goroutine? by using one amqp.Connection
or
Is there any connection pooling method?
@michaelklishin
publishing and consuming on the same channel is not right, how about publishing and consuming on the different channel with one connection ?
Most helpful comment
@michaelklishin
publishing and consuming on the same channel is not right, how about publishing and consuming on the different channel with one connection ?