dart_amqp
dart_amqp copied to clipboard
Client timeout handling
Hi,
Any example of handling the client timeout?? and also can we set the timeout length manually??
Thanks.
I use this code after send and create listener consumer:
` String amqpMessageResponse; StreamSubscription<AmqpMessage> streamSubscriptionMessage; Duration timeout = new Duration(seconds: 10);
streamSubscriptionMessage = consumerForListen.listen(
(AmqpMessage amqpMessage) {
print('consumerForListen -> onMessage, amqpMessage: ' + amqpMessage.payloadAsString);
},
);
print('start listen');
waitingForMessage = true;
int counter = 0;
int waitingMillisec = 0;
do {
print('listen counter: ' + counter.toString());
streamSubscriptionMessage.onData((amqpMessage) {
try {
print('streamSubscriptionMessage -> onData, amqpMessage: ' + amqpMessage.payloadAsString);
} catch (e) {}
if (amqpMessage.payloadAsString == 'Test') {
amqpMessageResponse = amqpMessage.payloadAsString;
waitingForMessage = false;
}
});
if (waitingForMessage) {
await Future.delayed(const Duration(milliseconds: 500));
waitingMillisec += 500;
if (waitingMillisec > timeout.inMilliseconds) {
waitingForMessage = false;
}
}
counter++;
} while (waitingForMessage);`
try{
await streamSubscriptionMessage.cancel();
}
catch(e){
}