IMessageReceiver

Callback interface to receive incoming messages.

Description

The IMessageReceiver interface is used to receive incoming messages.

Instance methods

receiveMessage

Receives an incoming message from the queue.

See also MessageEnvelope, IMessageQueue

Future receiveMessage(MessageEnvelope envelope, IMessageQueue queue)

Examples

import 'package:pip_services3_messaging/pip_services3_messaging.dart';

void main(List<String> argument) async {
  var messageQueue = MemoryMessageQueue();
  messageQueue.listen('123', MyMessageReceiver());
  await messageQueue.open('123');
  await messageQueue.send('123',
      MessageEnvelope(null, 'mymessage', 'ABC')); // Output in console: "ABC"
  await Future.delayed(Duration(milliseconds: 500));
  await messageQueue.close('123');
}

class MyMessageReceiver implements IMessageReceiver {
  @override
  Future receiveMessage(MessageEnvelope envelope, IMessageQueue queue) async {
    print('Received message: ' + envelope.getMessageAsString());
  }
}