A Dart-native lightweight Apache Pulsar client primarily focused on the IoT telemetry domain

Overview

pulsar_iot_client

A lightweight Apache Pulsar client primarily focused on the IoT telemetry domain. This project aims to improve the resulting performance of a Pulsar cluster / reduce operating costs by removing the AMQP / MQTT proxy and utilizing the message batching.

Core features:

  • fully asynchronous API (Producer, Consumer)
  • transparent topic rebalancing handling (producer/consumer recreated on a new broker)
  • supports message batching. In fact, each batch message is stored as a single ledger entry on the Pulsar side, making this a preferable way of relatively small periodic data updates handling
  • OAuth2 / token-based authentication with access token refreshing support
  • TLS-forced mode to impose app security

TODO:

  • partitioned topics support
  • payload schema support

Quick start

Producer

// PulsarClient is an entry point
var client = PulsarClient(
  settings: PulsarClientSettings(
    serviceUrl: 'pulsar://localhost:6650',
  ),
);

// global errors (not associated with individual requests completion)
client.clientErrorStream.listen((Object error) {
});

// create Producer on the topic
var producer = await client.newProducer(
  ProducerCreateParams(topic: 'persistent://tenant/namespace/topic')
);

// send a single message. Result contains the messageId
var resultSingle = await producer.sendMessage(
  GenericMessage(
    propertyMap: {'key': 'value'},
    payload: Uint8List.fromList('Binary payload'.codeUnits),
  )
);

// close individual producer
producer.close();
// close client (with all associated producers, consumers and broker connections)
client.close();

Consumer

// create Consumer on the topic with defined subscription name and type
var consumer = await client.newConsumer(
  ConsumerCreateParams(
      topic: 'persistent://tenant/namespace/topic',
      subscription: 'subscription-name',
      subType: SubscriptionType.exclusive,
  )
);

// listen for incoming messages
consumer.listen((GenericInputMessage message) {
  // ack message (unless it's intermediate in a batch) 
  if (message.storageType != MessageStorageType.batchIntermediate) {
    consumer.ackMessage(message.messageId, false);
  }
});

// give permission to the broker to push next 100 messages (flow control)
await consumer.getFlow(100);

OAuth2 (using oauth2 package)

Future<String> _getAuthToken(String? data) {
  var completer = Completer<String>();

  // alternatively, call refreshCredentials() on existing oauth2 client if supported by the particular grant type 
  oauth2.clientCredentialsGrant(
    oauth2Endpoint,
    oauth2Identifier,
    oauth2Secret,
  )
  .then((oauth2client) {
    completer.complete(oauth2client.credentials.accessToken);
  })
  .catchError((error, trace) { completer.completeError(error, trace); });

  return completer.future;
}

// The authTokenProvider function will be invoked to get/refresh an access token
// The periodic token refresh will be triggered by broker, there's no need to track expiration manually
var client = PulsarClient(
  settings: PulsarClientSettings(
    forceTLS: true,
    serviceUrl: 'pulsar+ssl://broker.my-domain.com:6651',
    authTokenProvider: _getAuthToken,
    authTokenRefreshSupported: true,
  ),
);
You might also like...

Cross-platform mobile app for tracking GPS with IoT technologies.

Cross-platform mobile app for tracking GPS with IoT technologies.

IoT Tracking Cross-platform mobile app for tracking GPS with IoT technologies. Table of Contents Introduction Requirements Installation Build & Run Kn

Oct 2, 2022

đź’–A free IoT (Internet of Things) platform and private cloud

đź’–A free IoT (Internet of Things) platform and private cloud

Nov 30, 2022

CartToGo is an IoT-based smart system that is connected to an iOS mobile application

CartToGo is an IoT-based smart system that is connected to an iOS mobile application

CartToGo is an IoT-based smart system that is connected to an iOS mobile application, used by supermarket shoppers to reduce their waiting time in the queue lines and that’s done by enabling them to scan each product’s barcode to display its price and total price on the LCD display as well as the iOS mobile application.

Dec 15, 2022

IoTF app is a smart farming app for IoT and AI-powered tomato plant disease detection. It is built with Flutter and uses Firebase as its backend.

Internet of Tomato Farming IoTF app is a smart farming app for IoT and AI-powered tomato plant disease detection. It is built with Flutter and uses Fi

Dec 9, 2022

It is an IoT smart home app

It is an IoT smart home app

Smart Home Our world is increasingly interconnected - most of us own a smartphone and can access all kinds of information right from our pockets. From

Dec 26, 2022

Merixstudio’s IoT meeting room booking system

Merixstudio’s IoT meeting room booking system

Chamberlain This project is in the open-sourcing process. There is only a mobile application available right now. The Firebase project will be availab

Sep 30, 2022

The domain specific language in dart for flutter widgets.

The domain specific language in dart for flutter widgets.

Rettulf !esrever ni stegdiw etirW Getting started import 'package:rettulf/rettulf.dart'; void main() = const MyApp().runAsApp(); class MyApp extend

Dec 21, 2022

A mobile application that allows you to search and fetch recipes using Flutter, TheMealDB and Domain Driven Design

recipe_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Dec 4, 2021

Crypto Loss Gain Calculator App build with Flutter. It developed with DDD (Domain Driven Design) principles.

Crypto Loss Gain Calculator App build with Flutter. It developed with DDD (Domain Driven Design) principles.

Crypto Loss Gain Calculator Crypto Loss Gain Calculator App build with Flutter. It developed with DDD (Domain Driven Design) principles. Domain-Driven

Dec 27, 2022
Owner
Mike Zolotarov
Mike Zolotarov
dna, dart native access. A lightweight dart to native super channel plugin

dna, dart native access. A lightweight dart to native super channel plugin, You can use it to invoke any native code directly in contextual and chained dart code.

Assuner 14 Jul 11, 2022
A Flutter Weather App primarily developed to showcase my technical knowledge as well as practices I believe are the best.

Weather One This is a Flutter Weather App primarily developed to showcase my technical knowledge as well as practices I believe are the best. The weat

Phumudzo Muvhango 1 Apr 27, 2022
Lightweight internet connection test, lookup a domain.

palestine_connection Lightweight internet connection test, lookup Google domain. Part of PalestineDevelopers project Features Periodic internet connec

Palestine Developers 5 Jun 26, 2022
GrowERP Flutter Administrator front-end & Hotel & Ecommerce for Android, IOS and Web using Moqui.org, Apache OFBiz

Welcome to flutter open source GrowERP. GrowERP is an open source multi platform ERP application you can try right now! We have latest test version at

GrowERP 11 Dec 24, 2022
🚀 Sample Flutter Clean Architecture on Rorty App focused on the scalability, testability and maintainability written in Dart, following best practices using Flutter.

Rorty Flutter Rorty ?? (work-in-progress for V2 ?? ??️ ??‍♀️ ⛏ ) Getting Started Flutter Clean Architecture in Rorty is a sample project that presents

Mr.Sanchez 138 Jan 1, 2023
A lightweight and customizable http client that allows you to create offline-first dart app easily.

Enjoyable & customizable offline-first REST API client Unruffled is lightweight and customizable http client that allows you to create offline-first e

T. Milian 3 May 20, 2022
This is a set of small projects focused solely on the development of the graphical interface with Flutter

My Flutter Projects Flutter apps with cool design and animations Social Media Youtube Facebook Twitter Getting Started This project is a starting poin

Kevin Melendez 500 Dec 19, 2022
Create a Grid Layout of IoT (Internet of Things) devices in a particular house.

Create a Grid Layout of IoT (Internet of Things) devices in a particular house. Keep it simple to just 4-6 devices. Each device will have an icon on its own. When you press the icon, toggle the image and toggle the text underneath between on and off.

null 0 Dec 30, 2021
A movies app made with Flutter focused on solid software structure patterns.

Flutter Movies App An application made with Flutter to practice the principles of Clean Architecture. Even being focused on architecture, the project

Márcio Valim 59 Dec 12, 2022
A Launcher focused on simplicity and legibility.

Elder Launcher Elder Launcher is a launcher designed for seniors focused on simplicity and legibility. Elder Launcher supports pinning favorite apps a

Arjunsinh Jadeja 30 Dec 5, 2022