搜索插件、代码仓与 APP 分类

插件详情v0.3.1

dart_amqp

一个原生的 Dart AMQP 客户端,支持 AMQP 协议的 0.9.1 版本。它具有异步 API、可插拔的身份验证提供程序和 TLS 支持。

AndroidiOSmacOSWindowsLinux
近 30 天下载
7500
喜欢数
63
Pub 分数
150

安装插件

flutter pub add dart_amqp

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

dart_amqp 是 AMQP 0.9.1 协议的原生 Dart 客户端,可在 Dart 应用中实现实时通信。它提供异步 API 以高效处理消息,支持 TLS 加密以确保连接安全,并允许使用可插拔的身份验证机制。非常适合与消息代理(如 RabbitMQ)集成,可在跨平台环境中实现可靠且低延迟的消息传递。

适合场景

  • 实时消息系统
  • 物联网设备通信
  • 事件驱动的后端服务
  • 实时流数据管道
  • 微服务协调

主要特点

  • AMQP 0.9.1 协议支持
  • 异步API设计
  • TLS 加密
  • 可插拔身份验证
  • 跨平台兼容性

适合对象

  • 开发实时应用的开发者
  • 使用 RabbitMQ 的团队
  • 需要安全消息传递的应用程序
  • 需要事件路由的后端服务
  • 跨平台 Dart 项目

使用建议

  • 需要 AMQP 代理(例如 RabbitMQ)
  • 限制为 AMQP 0.9.1
  • 需要设置身份验证
  • 不适合非实时使用场景
  • 无内置消息持久化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

dart_amqp

Build Status Coverage Status

Dart AMQP client implementing protocol version 0.9.1

Main features:

  • asynchronous API based on Futures and Streams
  • supports PLAIN and AMQPLAIN authentication providers while other authentication schemes can be plugged in by implementing the appropriate interface.
  • implements the entire 0.9.1 protocol specification (except basic get and recover-async).
  • supports both plain-text and TLS connections.
  • supports publish confirmations.
  • supports heartbeats.

Things not working yet:

  • the driver does not currently support recovering client topologies when re-establishing connections. This feature may be implemented in a future version.

Quick start

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

API

See the API documentation.

RPC calls over AMQP

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.

Examples

The example folder contains implementations of the six RabbitMQ getting started tutorials.

Contributing

See the Contributing Guide.

License

dart_amqp is distributed under the MIT license.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目