on method
Future<void>
on(
- BlobEventType blobEventType,
- String keyPrefixFilter,
- BlobEventHandler handler, {
- List<
BlobEventHandler> middlewares = const [],
Create a blob event subscription triggered on the blobEventType
filtered by files that match the keyPrefixFilter
.
Implementation
Future<void> on(BlobEventType blobEventType, String keyPrefixFilter,
BlobEventHandler handler,
{List<BlobEventHandler> middlewares = const []}) async {
// Create the request to register the Storage listener with the membrane
final eventType = switch (blobEventType) {
BlobEventType.write => $bp.BlobEventType.Created,
BlobEventType.delete => $bp.BlobEventType.Deleted,
};
final registrationRequest = $bp.RegistrationRequest(
bucketName: name,
keyPrefixFilter: keyPrefixFilter,
blobEventType: eventType,
);
final composedHandler =
composeMiddleware([...middlewares, handler], BlobEventContext.fromCtx);
var worker = BlobEventWorker(registrationRequest, composedHandler);
await worker.start();
}