Skip to content

Declare RabbitMQ exchange before publishing messages#9393

Open
ittennull wants to merge 1 commit intoChilliCream:mainfrom
ittennull:declare-exchange
Open

Declare RabbitMQ exchange before publishing messages#9393
ittennull wants to merge 1 commit intoChilliCream:mainfrom
ittennull:declare-exchange

Conversation

@ittennull
Copy link
Copy Markdown
Contributor

RabbitMQ requires an exchange to exist in order to publish a message to it, otherwise it returns an error and the whole channel becomes unusable. The code uses ConcurrentDictionary to remember which exchanges were declared. It is faster than calling the function before each publish.

The problem that this PR fixes appears when an application starts publishing updates to graphql subscription before a client connects to it. Since the queue and the exchange were created only on consumer side, the producer always failed if it was too fast because it couldn't publish to a non-existent exchange. Even worse - the whole channel got closed and all consumers and producers, even those that had create-first-publish-second approach, started to fail.

RabbitMQ requres an exchange to exist, otherwise it returns an error and the whole channel becomes unusable.
The code uses ConcurrentDictionary to remember which exchanges were declared. It is faster than calling the function before each publish.
Copy link
Copy Markdown
Member

@michaelstaib michaelstaib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually introduces more issues to the implementation and also introduces channel handling that is explicitly called our in the RabbitMQ docs to not do.

We will do a general review of the subscription providers after 16 is out.

@ittennull
Copy link
Copy Markdown
Contributor Author

Could you elaborate: what problems does it introduce and what exactly is advised not to do in the docs?

@ittennull
Copy link
Copy Markdown
Contributor Author

This actually introduces more issues

If I know what you mean, I can probably fix it

@ittennull ittennull requested a review from michaelstaib March 24, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants