Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Sending and Publishing on the same channel #270

Closed
fho opened this issue May 19, 2017 · 8 comments
Closed

Question: Sending and Publishing on the same channel #270

fho opened this issue May 19, 2017 · 8 comments

Comments

@fho
Copy link

fho commented May 19, 2017

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?

@fho fho changed the title Sending and Publishing on the same channel Question: Sending and Publishing on the same channel May 19, 2017
@michaelklishin
Copy link
Collaborator

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?

@fho
Copy link
Author

fho commented May 21, 2017

@michaelklishin thanks for your reply.
What do you mean with "resource alarms"?

@michaelklishin
Copy link
Collaborator

@fho see documentation.

@fho
Copy link
Author

fho commented May 21, 2017

@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?

@michaelklishin
Copy link
Collaborator

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 962fd41 5 years ago. Perhaps @streadway can remember what it was about.

@ytkang
Copy link

ytkang commented Aug 9, 2018

@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?

@zzybooboo
Copy link

@michaelklishin
publishing and consuming on the same channel is not right, how about publishing and consuming on the different channel with one connection ?

@legacy-dev6
Copy link

@michaelklishin publishing and consuming on the same channel is not right, how about publishing and consuming on the different channel with one connection ?

i would like to know more about this thought ..any thoughts ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants