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

MF-1681 - Failed to reconnect to NATS #1686

Merged
merged 2 commits into from
Dec 21, 2022
Merged

Conversation

dborovcanin
Copy link
Collaborator

Signed-off-by: dusanb94 dusan.borovcanin@mainflux.com

What does this do?

Currently, connection to NATS defaults to a max of 60 reconnect attempts before giving up and leaving the connection permanently closed. This approach causes the problem in case the service has been disconnected from the NATS server for whatever reasons.
This pull request makes a connection to NATS to never give up on trying to reconnect.

Which issue(s) does this PR fix/relate to?

This pull request fixes #1681.

List any changes that modify/break current functionality

There are no such changes.

Have you included tests for your changes?

N/A

Did you document any new/modified functionality?

N/A

Notes

N/A

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
@dborovcanin dborovcanin requested a review from a team as a code owner December 21, 2022 10:48
@@ -22,7 +22,7 @@ type publisher struct {

// NewPublisher returns NATS message Publisher.
func NewPublisher(url string) (messaging.Publisher, error) {
conn, err := broker.Connect(url)
conn, err := broker.Connect(url, broker.MaxReconnects(-1))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would define this constant somewhere and give it a self-documenting name, like tryForever, or you can leave a comment what this -1 means (for someone reading the code for the first time)

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit f438d24 into absmach:master Dec 21, 2022
rodneyosodo pushed a commit to rodneyosodo/magistrala that referenced this pull request Feb 2, 2023
* Make NATS reconnect never give up

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Extract maxReconnects to a constant

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
@dborovcanin dborovcanin deleted the MF-1681 branch January 12, 2024 09:49
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

Successfully merging this pull request may close these issues.

Failed to reconnect to NATS
2 participants