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
When close() is called on a link that got closed due to external factors, the listeners are not cleared #30
Comments
Sample code for the following description: import {
Connection, EventContext, ConnectionOptions, Receiver, ReceiverEvents
} from "rhea-promise";
import { ConnectionEvents } from "rhea";
const host = " ";
const username = "";
const password = "";
const port = 5671;
const receiverAddress = "";
async function main(): Promise<void> {
const connectionOptions: ConnectionOptions = {
transport: "tls",
host: host,
hostname: host,
username: username,
password: password,
port: port,
reconnect: false
};
const connection: Connection = new Connection(connectionOptions);
await connection.open();
const receiver: Receiver = await connection.createReceiver({
name: "receiver-1",
source: {
address: receiverAddress
},
});
receiver.on(ReceiverEvents.message, (context: EventContext) => {
console.log("Received message: %O", context.message);
});
receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
if (context.receiver && context.receiver.error) {
console.log(">>>>> An error occurred for receiver: %O.", context.receiver.error);
}
});
const disconnected: any = async (context: EventContext) => {
console.log("Disconnected Event Fired");
const connectionError = context.connection && context.connection.error
? context.connection.error
: context.error;
if (connectionError) {
console.log("Error occurred on the amqp connection: %O", connectionError);
}
console.log(`Reciever is open?: ${receiver.isOpen()}`);
console.log(`ListenerCount for message event: ${receiver.listenerCount(ReceiverEvents.message)}`);
console.log(`ListenerCount for error event: ${receiver.listenerCount(ReceiverEvents.receiverError)}`);
await receiver.close();
console.log(`After close ListenerCount for message event: ${receiver.listenerCount(ReceiverEvents.message)}`);
console.log(`After close ListenerCount for error event: ${receiver.listenerCount(ReceiverEvents.receiverError)}`);
};
connection.on(ConnectionEvents.disconnected, disconnected);
}
main().catch((err) => console.log(err)); |
While using the above sample code to receive messages, disable the network connection. You will see the handler for the
|
Related issue in rhea: amqp/rhea#205 |
As per discussions in amqp/rhea#205, it is concluded that it is the consumer's responsibility to call Keeping this issue open to track the need for |
@amarzavery,
Say a link gets closed due to external factors (one way is to disable internet connection in the midst of receiving messages) i.e. no-one called
link.close()
, butlink.isOpen()
returnsfalse
.What is the suggested way for consumers of
rhea-promise
to clean up the link?link.close() clears only the
close
anderror
event listeners that were attached inside theclose()
function, but not the listeners for all other events that were attached in the _initializeEventListeners function.Calling link.remove() at this point does clear the listeners, but I am not sure if this is the right way to go about it.
I would expect
link.close()
to do the right thing here.cc @ShivangiReja
The text was updated successfully, but these errors were encountered: