Skip to content

Improve nats Client Connection Logic #863

@sergeyWh1te

Description

@sergeyWh1te

Description

The current implementation of the nats NewClient function in codebase has a few areas that need improvement for better connection management and logging. The following issues have been identified:

Redundant Connection Attempts:
- The current implementation attempts to connect to the NATS server in a loop, retrying up to 10 times with a 1-second delay. This can lead to unnecessary retries and increased latency in establishing a connection.

Proposed Solution

  1. Simplifying Connection Logic:

    • Removing the loop for connection attempts and replacing it with a single connection attempt using NATS connection parameters such as ReconnectWait and MaxReconnects.
  2. Improving Error Handling:

    • Implementing NATS connection event handlers (DisconnectErrHandler, ReconnectHandler, and ClosedHandler) to provide detailed logs for connection lifecycle events.

#862

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions