dart_amqp_client
AMQP(고급 메시지 큐잉 프로토콜) 연결, 채널 및 관련 콜백 처리를 간소화하는 Dart 패키지입니다.
AMQP(고급 메시지 큐잉 프로토콜) 연결, 채널 및 관련 콜백 처리를 간소화하는 Dart 패키지입니다. AMQP 서버에 대한 연결을 설정하고 관리하기 위한 사용하기 쉬운 인터페이스를 제공하여, 저수준의 AMQP 세부 사항을 다루지 않고도 애플리케이션 로직에 집중할 수 있게 해줍니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Dart AMQP Client is a Dart package that simplifies the handling of AMQP (Advanced Message Queuing Protocol) connections, channels, and associated callbacks.
Connection Management: Automatically handles AMQP connection establishment and reconnection. Callback Support: Define custom callbacks for connection events, such as when the connection is established or encounters an error. Reconnection Control: Configure the maximum number of reconnection attempts for robust AMQP connections. Simple Integration: Easily integrate the package into your Dart applications with a straightforward API.
To use this package, add dart_amqp_client as a dependency in your pubspec.yaml file:
dependencies: dart_amqp_client: ^1.0.1
Then, run pub get to fetch and install the package.
import 'package:dart_amqp_client/dart_amqp_client.dart';
void main() {
// Create a ConnectionSettings instance with your AMQP server details.
ConnectionSettings connectionSettings = ConnectionSettings(
host: 'localhost',
port: 5672,
maxConnectionAttempts: 5, // Set the maximum connection attempts
);
// Create an instance of the AMQP service.
AmqpService(connectionSettings);
// Set callback functions for connection events.
AmqpService.onConnected(() {
print('Connected to AMQP server.');
// Use the service to establish an AMQP connection.
Client client = AmqpService.getClient();
// ... Perform AMQP operations with the client and channel ...
String consumeTag = "hello";
String msg = "Hello World!";
client.channel().then((Channel channel) {
return channel.queue(consumeTag, durable: false);
}).then((Queue queue) {
queue.publish(msg);
print(" [x] Sent $msg");
client.close();
});
String queueTag = "hello";
Channel? channel = AmqpService.getChannel();
channel!.queue(queueTag, durable: false).then((Queue queue) {
print(" [*] Waiting for messages in $queueTag. To Exit press CTRL+C");
return queue.consume(consumerTag: queueTag, noAck: true);
}).then((Consumer consumer) {
consumer.listen((AmqpMessage event) {
print(" [x] Received ${event.payloadAsString}");
});
});
});
AmqpService.onDisconnected(() {
print('Disconnected from AMQP server.');
});
AmqpService.onError((Exception error) {
print('An error occurred: $error');
});
}
The [example] folder contains implementations for getting started
Feel free to contribute
dart_amqp is distributed under the [MIT license]