dart_pgmq 1.0.0 copy "dart_pgmq: ^1.0.0" to clipboard
dart_pgmq: ^1.0.0 copied to clipboard

A dart client for Postgres Message Queue (PGMQ).

example/example.dart

import 'package:dart_pgmq/dart_pgmq.dart';

Future<void> main() async {
  // Create a DatabaseConnection
  final databaseParam = DatabaseConnection(
      host: 'localhost',
      database: 'postgres',
      password: 'postgres',
      username: 'postgres',
      ssl: false,
      port: 5460);

  // Create a connexion
  final pgmq = await Pgmq.createConnection(param: databaseParam);

  //  Create a queue
  final queue = await pgmq.createQueue(queueName: 'queueName');

  // Send message
  for (var i = 1; i <= 20; i++) {
    await Future.delayed(Duration(seconds: 3));
    final payload = {'id': i, 'message': 'message $i'};
    await queue.send(payload);
  }

  // Read message
  final data = (await queue.read(maxReadNumber: 5));
  for (final msg in data ?? <Message>[]) {
    print(msg.payload);
  }

  // Purge queue
  await queue.purgeQueue();
}
2
likes
150
points
35
downloads

Publisher

verified publisherofceabstudio.dev

Weekly Downloads

A dart client for Postgres Message Queue (PGMQ).

Repository (GitHub)
View/report issues

Topics

#postgresql #message-queue #pgmq

Documentation

API reference

License

MIT (license)

Dependencies

pausable_timer, postgres, postgresql2

More

Packages that depend on dart_pgmq