Thanks to visit codestin.com
Credit goes to github.com

Skip to content

rhea amqp with Solace best practices recommendation for stable and resilient connection #440

@ahmad-khet-1

Description

@ahmad-khet-1

Hi

I have used rhea amqp with Solace event broker, and I'm wondering if I followed the best practices, and recommended configurations for our code base.
the reason is that I faced a lot of unstable behaviors caused by disconnections either rhea session disconnection or network instabilities.

besides that I see a lot of logs about rhea is trying to create the queues in Solace, but as far as I know, that rhea does not support queues creation.

I will share chunks of the code for your review:
the goal is to have one stable and resilient amqp connection

class ConnectionManager {

private amqpConnection: Connection;
constructor() ... {
 this.amqpConnection = new Connection({
            host: '127.0.0.1',
            username: 'user',
            password: 'password',
            port: 5672,
            transport:'tls',
            reconnect: true,
            initial_reconnect_delay: 1000,
            max_reconnect_delay: 30000,
            all_errors_non_fatal: true,
      });
 this.amqpConnection.open();
}

...

}
class publisher {
 private sender: Sender;

constructor(amqConnection) {
..
}

async submit() {
 if (!this.sender || this.sender?.isClosed()) {
            this.sender = await this.amqpConnection.createSender({
                name: `sender1`,
                target: {
                    address: `topic://books/new`,
                    expiry_policy: 'never',
                    durable: 2,
                },
            });
    }

   this.sender.send({
                body: JSON.stringify(payload),
            });

}


}
class Subscriber {

    private receiver: Receiver;

constructor(amqConnection) {
..
}

async buildSubscriber () {

if (!this.receiver || this.receiver?.isClosed()) {
                this.receiver = await this.amqpConnection?.createReceiver({
                    onMessage: (context: EventContext) => {
                       ....
                       ....
                       
                      context.delivery.accept()
                   }
                        
                    onError: (context: EventContext) => {
                       console.log("ERROR");
                    },
                    name: `Receiver-1`,
                    source: {
                        address: `queue://books/new`,
                        durable: 2,
                        expiry_policy: 'never',
                    },
                    autoaccept: false,
                });
}
}

}

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