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

Unexpacted behavor of channel.IsClosed() #14

Closed
kaibox-git opened this issue Sep 2, 2021 · 3 comments
Closed

Unexpacted behavor of channel.IsClosed() #14

kaibox-git opened this issue Sep 2, 2021 · 3 comments

Comments

@kaibox-git
Copy link

kaibox-git commented Sep 2, 2021

The code sends two messages in sequence - first is bad and next one is good:
err := channel.Publish("Exchange_does_not_exist", .....)
/* here err == nil /
/
message is not delivered - exchange does not exist - ok, but channel.IsClosed() == false !! */
err := channel.Publish(good_message)
here err == nil
channel.IsClosed() == false !!
message is not delivered with no error. It was sent to an emptiness...
In some seconds channel.IsClosed() becomes "true"...
I am forced to check the channel status with channel.QueueInspect() - it works.
Question:
Why channel.Publish() always returns nil?
Why channel.IsClosed() switches to true not at once and some subsequent valid messages go to emptiness with no error?

@malc0mn
Copy link

malc0mn commented Feb 19, 2022

Maybe the channel Publish documentation gives you some options (if I understand your problem correctly):

Publish sends a Publishing from the client to an exchange on the server.

When you want a single message to be delivered to a single queue, you can
publish to the default exchange with the routingKey of the queue name.  This is
because every declared queue gets an implicit route to the default exchange.

Since publishings are asynchronous, any undeliverable message will get returned
by the server.  Add a listener with Channel.NotifyReturn to handle any
undeliverable message when calling publish with either the mandatory or
immediate parameters as true.

Publishings can be undeliverable when the mandatory flag is true and no queue is
bound that matches the routing key, or when the immediate flag is true and no
consumer on the matched queue is ready to accept the delivery.

This can return an error when the channel, connection or socket is closed.  The
error or lack of an error does not indicate whether the server has received this
publishing.

It is possible for publishing to not reach the broker if the underlying socket
is shut down without pending publishing packets being flushed from the kernel
buffers.  The easy way of making it probable that all publishings reach the
server is to always call Connection.Close before terminating your publishing
application.  The way to ensure that all publishings reach the server is to add
a listener to Channel.NotifyPublish and put the channel in confirm mode with
Channel.Confirm.  Publishing delivery tags and their corresponding
confirmations start at 1.  Exit when all publishings are confirmed.

When Publish does not return an error and the channel is in confirm mode, the
internal counter for DeliveryTags with the first confirmation starts at 1.

And right below that, the documentation for PublishWithDeferredConfirm:

PublishWithDeferredConfirm behaves identically to Publish but additionally returns a
DeferredConfirmation, allowing the caller to wait on the publisher confirmation
for this message. If the channel has not been put into confirm mode,
the DeferredConfirmation will be nil.

@DanielePalaia
Copy link
Contributor

Hi, I don't think this is really an issue.
As @malc0mn explained posting the documentation Publish is asynchronous.

It will just return error in this case:

// Since publish is asynchronous this can happen if the network connection
// is reset or if the server has run out of resources.

You can use channel confirm with PublishWithDeferredConfirm plus channel Wait if you need a blocking DeferredConfirmation.

@DanielePalaia
Copy link
Contributor

HI, I will close this issue, hope the response has been useful to you. Please check also our integration tests to see how Confirm and NotifyPublish (TestIntegrationConfirm) or PublishWithDeferredConfirm works. Feel free to open a new Issue or discussion in case you have further questions/issues

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

No branches or pull requests

3 participants