我使用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)
并且总消息为零:
是否可以在一个频道中发送和接收消息?
如果我在RabbitMQ Managment中使用client1.subscribeString(ack: CLIENT,...)
,我会得到一条消息&#34;在内存中#34;但测试仍然Test timed out
,我无法从mq收到消息。
也许我必须设置amq.fanout交换,但我该怎么做呢?