Search code examples
rabbitmqdartstomp

Dart and RabbitMQ bind exchange


I use STOMP package, and I wrote a test:

test('can subscribe and send events to mq server', () async {
  StompClient client2 = await serverClient.connect(mqIp,
      port: mqPort, login: login, passcode: password);

  client2.sendJson('Domain changed', {'a':'b'});
  client2.disconnect();

  StreamController controller = new StreamController();
  Stream<String> stream = controller.stream.asBroadcastStream();

  StompClient client1 = await serverClient.connect(mqIp,
      port: mqPort, login: login, passcode: password);

  client1.subscribeString("Entity changed", 'Domain changed',
      (Map<String, String> headers, String message) {
    controller.add(message);
  }, ack: AUTO);

  await for (String message in stream) {
    String expectedEntity =
        '{\"a\":\"b\"}';
    expect(message, equals(expectedEntity));
    break;
  }

  client1.unsubscribe("Entity changed");
  client1.disconnect();
}, timeout: new Timeout(new Duration(seconds: 6)));

When I run pub run test I get Test timed out.

In RabbitMQ Managment in bindings section I get: (Default exchange binding) and zero in total messages:

enter image description here

Is it possible to send and recive messages in one channel?

If I use client1.subscribeString(ack: CLIENT,...) in RabbitMQ Managment I get one message "In memory" but test still Test timed out and I can't get message from mq. enter image description here

Maybe I must set up amq.fanout exchange, but how I can do this?


Solution

  • Best choice for use RabbitMq with dart: mqtt package