dart_amqp
一個原生的 Dart AMQP 客戶端,支援 AMQP 協定的 0.9.1 版本。它具備非同步 API、可插入的身份驗證提供者以及 TLS 支援。
Dart AMQP 客戶端,實現協議版本 0.9.1
以下為英文專案原文快照,最新內容請造訪 GitHub。
Build Status Coverage Status
Dart AMQP client implementing protocol version 0.9.1
Main features:
Things not working yet:
Listening to a queue:
import "package:dart_amqp/dart_amqp.dart";
void main() async {
Client client = Client();
Channel channel = await client.channel(); // auto-connect to localhost:5672 using guest credentials
Queue queue = await channel.queue("hello");
Consumer consumer = await queue.consume();
consumer.listen((AmqpMessage message) {
// Get the payload as a string
print(" [x] Received string: ${message.payloadAsString}");
// Or unserialize to json
print(" [x] Received json: ${message.payloadAsJson}");
// Or just get the raw data as a Uint8List
print(" [x] Received raw: ${message.payload}");
// The message object contains helper methods for
// replying, ack-ing and rejecting
message.reply("world");
});
}
Sending messages via an exchange:
import "package:dart_amqp/dart_amqp.dart";
void main() async {
// You can provide a settings object to override the
// default connection settings
ConnectionSettings settings = ConnectionSettings(
host: "remote.amqp.server.com",
authProvider: PlainAuthenticator("user", "pass")
);
Client client = Client(settings: settings);
Channel channel = await client.channel();
Exchange exchange = await channel.exchange("logs", ExchangeType.FANOUT);
// We dont care about the routing key as our exchange type is FANOUT
exchange.publish("Testing 1-2-3", null);
client.close();
}
See the API documentation.
This example illustrates how to get a basic RPC server/client up and running using just the provided api calls.
The driver does not provide any helper classes for easily performing RPC calls over AMQP as not everyone needs this functionality. If you need RPC support for your application you may want to consider using the dart_amqp_rpc package.
The example folder contains implementations of the six RabbitMQ getting started tutorials.
See the Contributing Guide.
dart_amqp is distributed under the MIT license.