Dart和RabbitMQ绑定交换

时间:2017-07-25 13:51:09

标签: rabbitmq dart stomp

我使用STOMP package,我写了一个测试:

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)));

当我运行pub run test时,我得到Test timed out

在绑定部分的RabbitMQ管理中,我得到:(Default exchange binding)并且总消息为零:

enter image description here

是否可以在一个频道中发送和接收消息?

如果我在RabbitMQ Managment中使用client1.subscribeString(ack: CLIENT,...),我会得到一条消息&#34;在内存中#34;但测试仍然Test timed out,我无法从mq收到消息。 enter image description here

也许我必须设置amq.fanout交换,但我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

使用带有飞镖的RabbitMq的最佳选择:mqtt package