utopia_queue 0.3.0 copy "utopia_queue: ^0.3.0" to clipboard
utopia_queue: ^0.3.0 copied to clipboard

Light and easy to use queue library for Dart server projects

Utopia Queue #

Utopia queue is a powerful queue library. It is designed to be simple and easy to learn and use. It is built on top of redis.

It is super helpful to build background workers to handle long running tasks. For example in your API server, you can use a emails queue to handle sending emails in the background.

Getting started #

First add the dependency in your pubspec.yaml

dependencies:
  utopia_queue: ^0.2.0

Now, in main.dart, you can start a server as the following.

import 'package:utopia_queue/utopia_queue.dart';

void main(List<String> arguments) async {
  final connection = ConnectionRedis('localhost', 6379);
  final Server server = Server(connection, queue: 'myqueue');

  server.job().inject('message').action((Message message) {
    print(message.toMap());
    // Do something with the message
  });
  server.start();
}

To send a message to the queue, use the following code.

import 'dart:io';
import 'dart:math';

import 'package:utopia_queue/utopia_queue.dart';

void sendMessage() async {
  final connection = ConnectionRedis('localhost', 6379);
  final client = Client(connection, queue: 'myqueue');
  await client
      .enqueue({'user': Random().nextInt(20), 'name': 'Damodar Lohani'});
  print('enqueued');
}
1
likes
150
pub points
0%
popularity

Publisher

verified publisherappwriters.dev

Light and easy to use queue library for Dart server projects

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

redis, utopia_di, uuid

More

Packages that depend on utopia_queue