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

Client timeout handling #39

Open
jeremy1265 opened this issue Feb 21, 2020 · 1 comment
Open

Client timeout handling #39

jeremy1265 opened this issue Feb 21, 2020 · 1 comment

Comments

@jeremy1265
Copy link

Hi,

Any example of handling the client timeout?? and also can we set the timeout length manually??

Thanks.

@korbacsk
Copy link

korbacsk commented Mar 9, 2020

I use this code after send and create listener consumer:

` String amqpMessageResponse;
StreamSubscription 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){
      
    }

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

No branches or pull requests

2 participants